annotate faptool.php @ 927:9a440921bbc2

Preview directory creation stuff.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 27 Nov 2014 18:03:43 +0200
parents 3bead6333500
children 980f15768103
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 <?
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 require_once "mconfig.inc.php";
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 require_once "msite.inc.php";
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 stCheckCLIExec();
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8
912
514d460c60a9 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
9 function wtExec($exe, $args, $expect = 0)
902
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
10 {
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
11 echo "@@EXEC: ".$exe." ".$args."\n";
912
514d460c60a9 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
12 exec(escapeshellcmd($exe)." ".$args, $output, $code);
514d460c60a9 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
13 if ($code !== $expect)
902
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
14 {
912
514d460c60a9 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
15 echo
514d460c60a9 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
16 "Error executing ".$exe.": ".$code."\n".$args."\n".
514d460c60a9 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
17 "------------------------------------------------\n".
514d460c60a9 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
18 implode("\n", $output).
514d460c60a9 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
19 "------------------------------------------------\n";
902
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
20 return FALSE;
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
21 }
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
22 return TRUE;
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
23 }
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
24
912
514d460c60a9 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
25
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
26 function wtExecOrDie($exe, $args)
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
27 {
902
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
28 if (wtExec($exe, $args) === false)
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
29 die();
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
30 }
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
31
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
32
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
33 function wtConvertImage($inFilename, $inFileType, $outFilename, $setDim, $setFormat, $setQuality, $thumb)
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
34 {
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
35 global $setPreviewPath;
912
514d460c60a9 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
36 $isTemp = FALSE;
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
37
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
38 if (($outDim = stGetSetting($setDim)) === FALSE ||
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
39 ($outFormat = stGetSetting($osetFormat)) === FALSE ||
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
40 ($outQuality = stGetSetting($setQuality)) === FALSE)
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
41 {
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
42 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
43 }
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
44
884
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
45 if ($inFileType == "gfx")
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
46 {
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
47 // Oh great .. we need gfxconv here because Imagick handles ILBM like shit
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
48 $filename = tempnam($setPreviewPath, "tmp");
912
514d460c60a9 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
49 $isTemp = TRUE;
514d460c60a9 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
50 if (wtExec(
884
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
51 "/usr/local/bin/gfxconv",
912
514d460c60a9 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
52 escapeshellarg($inFilename)." -f png -o ".escapeshellarg($filename)) === false)
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
514d460c60a9 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
55 if (!file_exists($filename))
514d460c60a9 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
56 {
514d460c60a9 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
57 echo "ERROR: gfxconv did not output a temporary conversion inbetween.\n";
514d460c60a9 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
58 return FALSE;
514d460c60a9 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
59 }
514d460c60a9 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
60
884
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
61 }
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
62 else
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
63 $filename = $inFilename;
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
64
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
65 // convert -resize 640x480 -background black -gravity center -extent 640x480
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
66 // -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
67
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
68 // Create conversion entity
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
69 $img = new Imagick($filename);
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
70 if ($img === false)
912
514d460c60a9 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
71 {
514d460c60a9 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
72 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
73 return FALSE;
514d460c60a9 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
74 }
884
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
75
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
76 // Get dimensions, setup background
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
77 $dim = $img->getImageGeometry();
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
78 $img->setBackgroundColor(imagick::COLOR_BLACK);
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
79 $img->setGravity(imagick::GRAVITY_CENTER);
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 // Act based on image size vs. desired size and $thumb mode
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
82 if ($thumb || $dim["width"] > $outDim[0] || $dim["height"] > $outDim[1])
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
83 {
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
84 // Image is larger
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
85 $img->resizeImage($outDim[0], $outDim[1], Imagick::FILTER_QUADRATIC, 1);
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
86 $img->setExtent($outDim[0], $outDim[1]);
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
87 $img->normalizeImage();
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
88 $img->unsharpMaskImage(0, 0.5, 1, 0.05);
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
89 }
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
90 else
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
91 if ($dim["width"] < $outDim[0] || $dim["height"] < $outDim[1])
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
92 {
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
93 // Image is smaller than requested dimension(s)?
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
94 $img->resizeImage($outDim[0], $outDim[1], Imagick::FILTER_POINT, 1);
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
95 $img->setExtent($outDim[0], $outDim[1]);
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
96 }
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
97
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
98 $img->setFormat($outFormat);
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
99 $img->setCompressionQuality($outQuality);
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
100
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
101 $img->stripImage();
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
102 $img->writeImage($outFilename);
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
103 $img->removeImage();
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
898
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
107 function wtRenderSample($inFilename, $outFilename)
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
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/openmpt123"
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
115 ,
926
3bead6333500 Do not use --render option.
Matti Hamalainen <ccr@tnsp.org>
parents: 925
diff changeset
116 "--quiet ".
884
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
117 "--samplerate ".$sfreq." ".
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
118 "--channels ".$schannels." ".
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
119 "--playtime ".$sduration." ".
898
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
120 escapeshellarg($inFilename)." -o ".escapeshellarg($outFilename));
882
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
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
123
898
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
124 function wtConvertSample($inFilename, $outFilename, $opts)
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
125 {
898
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
126 $sfreq = intval(stGetSetting("sampleFreq"));
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
127 $sduration = intval(stGetSetting("sampleDuration"));
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
128 $schannels = intval(stGetSetting("sampleChannels"));
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
129
898
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
130 foreach ($opts as $okey => $oval)
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
131 $optStr .= $okey." ".$oval." ";
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
132
902
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
133 return wtExec(
898
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
134 "/usr/local/bin/avconv",
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
135 "-y -t ".intval($sduration)." ".
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
136 "-i ".escapeshellarg($inFilename).
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
137 " ".$optStr." -ac ".$schannels.
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
138 " -map_metadata -1 ".
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
139 escapeshellarg($outFilename));
882
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
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
142
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
143 function wtPurgeDir($path)
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
144 {
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
145 if (file_exists($path))
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
146 wtExecOrDie("/bin/echo", "-fR ".escapeshellarg($path));
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
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
149
902
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
150 function wtUnpackArchiveTo($atype, $filename, $path)
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
151 {
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
152 // Check file type before doing anything
902
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
153 echo "Preparing to unpack archive file '".$filename."' ...\n";
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
154 switch ($atype)
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
155 {
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
156 case "LHA":
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
157 $exe = "/usr/bin/lha";
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
158 $args = "e ".escapeshellarg($filename);
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
159 break;
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 case "ZIP":
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
162 $exe = "/usr/bin/unzip";
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
163 $args = "-d ".escapeshellarg($path)." ".escapeshellarg($filename);
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
164 break;
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
165
898
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
166 case "RAR":
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
167 $exe = "/usr/bin/rar";
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
168 $args = "e ".escapeshellarg($filename);
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
169 break;
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
170
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
171 default:
902
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
172 echo "Unsupported archive file type: ".$atype."\n";
898
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
173 return FALSE;
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
174 }
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
175
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
176 // Create temporary directory
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
177 wtPurgeDir($path);
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
178 stMakeDir($path, 0700);
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
179
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
180 if (!is_dir($path) || chdir($path) === false)
902
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 echo "Failed to chdir to '".$path."', can't unpack archive.\n";
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
183 return FALSE;
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
184 }
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
185
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
186 // Unpack archive
902
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
187 return wtExec($exe, $args);
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
188 }
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
189
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
190
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
191 function wtScanArchive($efile, $filename)
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
192 {
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
193 global $setEntryPath;
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
194
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
195 $path = stMakePath(FALSE, FALSE, array($setEntryPath, "UNPACKS", $filename));
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
196
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
197 echo "Attempting to scan archive file '".$filename."' ...\n";
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
198
912
514d460c60a9 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
199 if (wtUnpackArchiveTo($efile["filetype"], $filename, $path) === false)
902
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
200 return FALSE;
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
201
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
202 // Scan through files ...
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
203 $dir = opendir($path);
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
204 while (($dentry = readdir($dir)) !== false)
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
205 {
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
206 }
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
207 closedir($dir);
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
208
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
209 wtPurgeDir($path);
902
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
210 return TRUE;
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
211 }
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
212
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
213
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 {
898
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
216 // Get current preview file data
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
217 if (!stGetPreviewFileData($compo, $entry, $pdata))
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
218 return FALSE;
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 if ($entry["file_id"] != 0)
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
221 $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
222 else
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
223 $efile = FALSE;
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
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
226 if ($mode == "sta")
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"],
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
230 ($efile !== false) ? "1" : ".",
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
231 isset($pdata["file"]) ? "2" : ".",
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
232 $pdata["valid"] ? "3" : ".",
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
233 $entry["name"]." by ".$entry["author"],
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 );
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
237 }
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
238 else
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
239 if ($mode == "upd")
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
240 {
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
241 /*
898
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
242 if (previewSourceFile does not exist)
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
243 {
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
244 if (entry is module file)
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
245 {
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
246 render sample
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
247 }
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
248 else
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
249 if (entry is image file)
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
250 {
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
251 convert image
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
252 }
898
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
253 else
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
254 if (entry is archive)
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
255 {
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
256 if compo preview type is image, scan archive for images ..
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
257 }
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
258 }
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
259
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
260 if (previewFiles older than previewSourceFile)
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
261 {
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
262 if (source == audio)
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
263 convert via avconv
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
264 else
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
265 if (source == image)
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
266 convert via imagick
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
267 }
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
268
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
269 // Based on compo / entry preview type ..
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
270
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
271 // Convert preview image file, if any
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
272 // Create thumbnail for it, too
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
273 wtConvertImage($inFilename, $outFilename,
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
274 "previewImageSize", "previewImageType",
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
275 "previewImageQuality", FALSE);
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
276
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
277 wtConvertImage($inFilename, $outFilename,
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
278 "previewThumbSize", "previewThumbType",
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
279 "previewThumbQuality", TRUE);
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
280 */
898
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
281 }
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
282 else
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
283 die("OMG!\n");
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
284 }
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
285
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
286
884
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
287 function wtHandleEntry($compo, $entry, $mode)
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
288 {
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
289 }
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
290
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
291
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
292 //
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
293 // Create directories
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
294 //
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
295 function stMakeDir($path, $perm)
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
296 {
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
297 if (!file_exists($path))
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
298 {
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
299 echo " - Creating ".$path."\n";
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
300 if (mkdir($path, $perm, TRUE) === false)
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
301 die("Could not create directory '".$path."'\n");
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
302 }
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
303 }
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
304
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
305
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
306 function stInitializeDirs()
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
307 {
902
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
308 global
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
309 $setEntryPath, $setPreviewPath, $setThumbDir,
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
310 $setEntryPathPerms, $setPrevPathPerms;
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
311
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
312 echo "Checking for missing directories ...\n";
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
313 stMakeDir($setEntryPath, $setEntryPathPerms);
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
314 stMakeDir($setPreviewPath, $setPrevPathPerms);
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
315
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
316 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
317 {
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
318 stMakeDir(stMakePath(FALSE, FALSE, array($setEntryPath, $compo["cpath"])), $setEntryPathPerms);
927
9a440921bbc2 Preview directory creation stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 926
diff changeset
319 stMakeDir(stMakePath(FALSE, FALSE, array($setPreviewPath, $compo["cpath"])), $setPrevPathPerms);
9a440921bbc2 Preview directory creation stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 926
diff changeset
320 stMakeDir(stMakePath(FALSE, FALSE, array($setPreviewPath, $compo["cpath"], $setThumbDir)), $setPrevPathPerms);
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
321 }
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
322 }
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
323
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
324
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
325 //
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
326 // Main program starts
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
327 //
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
328 if ($argc < 2)
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
329 {
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
330 echo
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
331 "faptool - Do stuff with FAPWeb database\n".
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
332 "(C) Copyright 2014 ccr/TNSP\n".
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
333 "\n".
917
eda104823649 Work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 912
diff changeset
334 "Usage: ".$argv[0]." <command> [args]\n".
eda104823649 Work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 912
diff changeset
335 "Where command is one of following:\n".
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
336 "\n".
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
337 " init\n".
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
338 " Create directories for entries and previews, if needed.\n".
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
339 "\n".
917
eda104823649 Work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 912
diff changeset
340 " clean [delete|crap]\n".
eda104823649 Work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 912
diff changeset
341 " 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
342 " any old or stale preview files and entry files.\n".
eda104823649 Work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 912
diff changeset
343 " Without 'delete' parameter just checks and shows what would deleted.\n".
eda104823649 Work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 912
diff changeset
344 " '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
345 " 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
346 " KNOW WHAT YOU ARE DOING!!!!!\n".
901
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
347 "\n".
925
5d53b9d6c319 Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 922
diff changeset
348 " probe <filename>\n".
5d53b9d6c319 Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 922
diff changeset
349 " Probe specified file for file information.\n".
5d53b9d6c319 Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 922
diff changeset
350 "\n".
881
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
351 " previews <cmd> [args]\n".
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
352 " Where <cmd> is one of:\n".
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
353 " status - List files and show what is missing, etc.\n".
901
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
354 "\n".
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
355 " entry <cmd> [args]\n".
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
356 " status - List entries for all compos.\n".
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
357 " unpack - Create subdirs and unpack archives under them.\n".
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
358 "\n";
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
359 exit;
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
360 }
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
361
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
362 // Try to connect to database
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
363 $spec = stGetSetting("sqlDB");
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
364 if (($db = stConnectSQLDBSpec($spec)) === false)
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
365 die("Could not connect to SQL database '".$spec."'.\n");
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
366
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
367 echo "Using database spec '".$spec."'.\n";
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
368
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
369 // Fetch non-"hardcoded" settings from SQL database
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
370 stReloadSettings();
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
371
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
372 // Set some globals for our benefit
922
b92549a3372d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 917
diff changeset
373 $setTermWidth = 75;
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
374 $setEntryPath = stGetSetting("entryPath");
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
375 $setPreviewPath = stGetSetting("previewPath");
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
376 $setPreviewURL = stGetSetting("previewURL");
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
377 $setThumbDir = stGetSetting("thumbnailSubDir");
832
Matti Hamalainen <ccr@tnsp.org>
parents: 831
diff changeset
378 $setEntryPathPerms = stGetSetting("entryPathPerms");
Matti Hamalainen <ccr@tnsp.org>
parents: 831
diff changeset
379 $setPrevPathPerms = stGetSetting("previewPathPerms");
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
380
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
381 if ($setEntryPath === FALSE || $setPreviewPath === FALSE ||
832
Matti Hamalainen <ccr@tnsp.org>
parents: 831
diff changeset
382 $setPreviewURL === FALSE || $setThumbDir === FALSE ||
Matti Hamalainen <ccr@tnsp.org>
parents: 831
diff changeset
383 $setEntryPathPerms === FALSE || $setPrevPathPerms === FALSE)
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
384 {
922
b92549a3372d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 917
diff changeset
385 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
386 }
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 // Act according to specified command
884
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
390 switch (substr(stCArgLC(1), 0, 3))
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
391 {
884
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
392 case "ini":
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
393 //
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
394 // Initialize the data directories etc
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
395 //
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
396 stInitializeDirs();
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
397 break;
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
398
925
5d53b9d6c319 Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 922
diff changeset
399 case "pro":
5d53b9d6c319 Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 922
diff changeset
400 {
5d53b9d6c319 Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 922
diff changeset
401 $filename = stCArg(2);
5d53b9d6c319 Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 922
diff changeset
402 if ($filename == "")
5d53b9d6c319 Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 922
diff changeset
403 die("No filename specified.\n");
5d53b9d6c319 Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 922
diff changeset
404
5d53b9d6c319 Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 922
diff changeset
405 if (($finfo = finfo_open()) === false)
5d53b9d6c319 Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 922
diff changeset
406 {
5d53b9d6c319 Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 922
diff changeset
407 stLogError("Internal error. Failed to initialize finfo().");
5d53b9d6c319 Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 922
diff changeset
408 return stError("Internal error, failed to probe file.");
5d53b9d6c319 Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 922
diff changeset
409 }
5d53b9d6c319 Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 922
diff changeset
410
5d53b9d6c319 Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 922
diff changeset
411 $sdata = @finfo_file($finfo, $filename, FILEINFO_NONE);
5d53b9d6c319 Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 922
diff changeset
412 $smime = @finfo_file($finfo, $filename, FILEINFO_MIME_TYPE);
5d53b9d6c319 Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 922
diff changeset
413 finfo_close($finfo);
5d53b9d6c319 Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 922
diff changeset
414
5d53b9d6c319 Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 922
diff changeset
415 echo
5d53b9d6c319 Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 922
diff changeset
416 "Probed: ".$sdata."\n".
5d53b9d6c319 Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 922
diff changeset
417 "Mime : '".$smime."'\n";
5d53b9d6c319 Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 922
diff changeset
418
5d53b9d6c319 Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 922
diff changeset
419 if (($finfo = stProbeFileInfo($filename)) !== false)
5d53b9d6c319 Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 922
diff changeset
420 print_r($finfo);
5d53b9d6c319 Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 922
diff changeset
421 }
5d53b9d6c319 Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 922
diff changeset
422 break;
5d53b9d6c319 Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 922
diff changeset
423
901
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
424 case "cle":
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
425 $doDelete = (stCArgLC(2) == "delete");
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
426 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
427 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
428 {
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
429 printf(
922
b92549a3372d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 917
diff changeset
430 "==%'=-".($setTermWidth-2)."s\n".
901
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
431 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
432 );
922
b92549a3372d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 917
diff changeset
433 echo str_repeat("-", $setTermWidth)."\n";
901
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
434
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
435 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
436 {
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
437 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
438 {
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
439 if ($efile["delete"] != 0)
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
440 {
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
441 echo "X";
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
442 }
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
443 }
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
444 }
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
445 echo "\n";
922
b92549a3372d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 917
diff changeset
446 echo str_repeat("-", $setTermWidth)."\n";
901
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
447 }
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
448 break;
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
449
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
450 case "ent":
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
451 //
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
452 // Entry files handling
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
453 //
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
454 $mode = substr(stCArgLC(2), 0, 3);
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
455 switch ($mode)
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
456 {
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
457 case "unp":
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
458 case "sta":
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
459 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
460 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
461 {
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
462 printf(
922
b92549a3372d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 917
diff changeset
463 "==%'=-".($setTermWidth-2)."s\n".
901
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
464 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
465 );
922
b92549a3372d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 917
diff changeset
466 echo str_repeat("-", $setTermWidth)."\n";
901
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
467
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
468 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
469 wtHandleEntry($compo, $entry, $mode);
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
470
922
b92549a3372d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 917
diff changeset
471 echo str_repeat("-", $setTermWidth)."\n";
901
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
472 }
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
473 break;
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
474
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
475 case "pac":
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
476 break;
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
477
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
478 case "add":
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
479 break;
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
480
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
481 default:
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
482 if ($mode == "")
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
483 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
484 else
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
485 die("ERROR! Invalid entry sub-command '".stCArg(2)."'.\n");
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
486 break;
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
487 }
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
488 break;
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
489
884
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
490 case "pre":
881
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
491 //
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
492 // Preview files handling
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
493 //
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
494 $mode = substr(stCArgLC(2), 0, 3);
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
495 switch ($mode)
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
496 {
898
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
497 case "upd":
881
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
498 case "sta":
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
499 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL") as $compo)
898
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
500 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
501 {
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
502 printf(
922
b92549a3372d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 917
diff changeset
503 "==%'=-".($setTermWidth-2)."s\n".
898
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
504 "PrevType : %s\n",
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
505 sprintf("[ #%03d - %s ]", $compo["id"], substr($compo["name"], 0, 40)),
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
506 $previewTypeList[$compo["preview_type"]][0]);
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
507
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
508 printf(" %-3s | %-3s | %-40s |\n",
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
509 "#ID", "FLG", "Entry name/author");
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
510
922
b92549a3372d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 917
diff changeset
511 echo str_repeat("-", $setTermWidth)."\n";
881
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
512
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
513 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
514 wtHandleEntryPreview($compo, $entry, $mode);
898
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
515
922
b92549a3372d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 917
diff changeset
516 echo str_repeat("=", $setTermWidth)."\n\n";
881
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
517 }
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
518 break;
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
519
901
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
520 case "add":
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
521 break;
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
522
881
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
523 default:
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
524 if ($mode == "")
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
525 die("ERROR! Previews command requires a sub-command argument.\n");
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
526 else
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
527 die("ERROR! Invalid previews sub-command '".stCArg(2)."'.\n");
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
528 break;
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
529 }
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
530 break;
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
531
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
532 default:
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
533 echo "ERROR! Invalid operation mode '".stCArg(1)."'.\n";
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
534 break;
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
535 }
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
536
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
537 ?>