827
|
1 #!/usr/bin/php
|
|
2 <?
|
|
3 require_once "mconfig.inc.php";
|
|
4 require_once "msite.inc.php";
|
|
5
|
|
6 stCheckCLIExec();
|
|
7
|
|
8
|
882
|
9 function wtExecOrDie($exe, $args)
|
|
10 {
|
|
11 echo "EXEC: ".$exe." ".$args."\n";
|
|
12 //passthru($exe." ".$args) == 0 or die("Error executing ".$exe.":\n".$args);
|
|
13 }
|
|
14
|
|
15
|
|
16 function wtConvertImage($inFilename, $inFileType, $outFilename, $setDim, $setFormat, $setQuality, $thumb)
|
|
17 {
|
|
18 global $setPreviewPath;
|
|
19
|
|
20 if (($outDim = stGetSetting($setDim)) === FALSE ||
|
|
21 ($outFormat = stGetSetting($osetFormat)) === FALSE ||
|
|
22 ($outQuality = stGetSetting($setQuality)) === FALSE)
|
|
23 {
|
|
24 die("Missing one of res/format/quality settings for '".$outFilename."'\n");
|
|
25 }
|
|
26
|
|
27 // convert -resize 640x480 -background black -gravity center -extent 640x480
|
|
28 // -unsharp "0x0.75+0.75+0.008" lol.lbm -quality 95 test.jpg
|
|
29 }
|
|
30
|
|
31
|
|
32 function wtRenderSample()
|
|
33 {
|
|
34 $sfreq = intval(stGetSetting("sampleFreq", 44100));
|
|
35 $sduration = intval(stGetSetting("sampleDuration", 30));
|
|
36 $schannels = intval(stGetSetting("sampleChannels", 1));
|
|
37
|
|
38 }
|
|
39
|
|
40
|
|
41 function wtConvertSample()
|
|
42 {
|
|
43 $sfreq = intval(stGetSetting("sampleFreq", 44100));
|
|
44 $sduration = intval(stGetSetting("sampleDuration", 30));
|
|
45 $schannels = intval(stGetSetting("sampleChannels", 1));
|
|
46
|
|
47 }
|
|
48
|
|
49
|
|
50 function wtPurgeDir($path)
|
|
51 {
|
|
52 if (file_exists($path))
|
|
53 wtExecOrDie("/bin/echo", "-fR ".escapeshellarg($path));
|
|
54 }
|
|
55
|
|
56
|
|
57 function wtScanArchive($compo, $efile, $filename)
|
|
58 {
|
|
59 global $setEntryPath;
|
|
60
|
|
61 $path = stMakePath(FALSE, FALSE, array($setEntryPath, "UNPACKS", $filename));
|
|
62
|
|
63 echo "Attempting to scan archive file '".$filename."' ...\n";
|
|
64
|
|
65 // Check file type before doing anything
|
|
66 switch ($efile["id"])
|
|
67 {
|
|
68 case "LHA":
|
|
69 $exe = "/usr/bin/lha";
|
|
70 $args = "e ".escapeshellarg($filename);
|
|
71 break;
|
|
72
|
|
73 case "ZIP":
|
|
74 $exe = "/usr/bin/unzip";
|
|
75 $args = "-d ".escapeshellarg($path)." ".escapeshellarg($filename);
|
|
76 break;
|
|
77
|
|
78 default:
|
|
79 die("Unsupported archive file type: ".$efile["id"]."\n");
|
|
80 }
|
|
81
|
|
82 // Create temporary directory
|
|
83 wtPurgeDir($path);
|
|
84 stMakeDir($path, 0700);
|
|
85
|
|
86 if (!is_dir($path) || chdir($path) === false)
|
|
87 die("Failed to chdir to ".$path."\n");
|
|
88
|
|
89 // Unpack archive
|
|
90 wtExecOrDie($exe, $args);
|
|
91
|
|
92 // Scan through files ...
|
|
93 $dir = opendir($path);
|
|
94 while (($dentry = readdir($dir)) !== false)
|
|
95 {
|
|
96 }
|
|
97 closedir($dir);
|
|
98
|
|
99 wtPurgeDir($path);
|
|
100 }
|
|
101
|
|
102
|
|
103 function wtHandleEntryPreview($compo, $entry, $mode)
|
|
104 {
|
|
105 /*
|
|
106 if (previewFile does not exist || previewFile older than entryFile)
|
|
107 {
|
|
108 if (entry is module file)
|
|
109 {
|
|
110 render sample
|
|
111 }
|
|
112 else
|
|
113 if (entry is image file)
|
|
114 {
|
|
115 convert image
|
|
116 }
|
|
117 }
|
|
118
|
|
119 // Based on compo / entry preview type ..
|
|
120
|
|
121 // Convert preview image file, if any
|
|
122 // Create thumbnail for it, too
|
|
123 wtConvertImage($inFilename, $outFilename,
|
|
124 "previewImageSize", "previewImageType",
|
|
125 "previewImageQuality", FALSE);
|
|
126
|
|
127 wtConvertImage($inFilename, $outFilename,
|
|
128 "previewThumbSize", "previewThumbType",
|
|
129 "previewThumbQuality", TRUE);
|
|
130 */
|
|
131 }
|
|
132
|
|
133
|
827
|
134 //
|
|
135 // Create directories
|
|
136 //
|
|
137 function stMakeDir($path, $perm)
|
|
138 {
|
|
139 if (!file_exists($path))
|
|
140 {
|
|
141 echo " - Creating ".$path."\n";
|
|
142 if (mkdir($path, $perm, TRUE) === false)
|
|
143 die("Could not create directory '".$path."'\n");
|
|
144 }
|
|
145 }
|
|
146
|
|
147
|
|
148 function stInitializeDirs()
|
|
149 {
|
|
150 global $setEntryPath, $setPreviewPath, $setThumbDir,
|
|
151 $setEntryPathPerms, $setPrevPathPerms;
|
|
152
|
|
153 echo "Checking for missing directories ...\n";
|
|
154 stMakeDir($setEntryPath, $setEntryPathPerms);
|
|
155 stMakeDir($setPreviewPath, $setPrevPathPerms);
|
880
|
156 stMakeDir(stMakePath(FALSE, FALSE, array($setPreviewPath, $setThumbDir)), $setPrevPathPerms);
|
827
|
157
|
|
158 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL") as $compo)
|
|
159 {
|
|
160 stMakeDir(stMakePath(FALSE, FALSE, array($setEntryPath, $compo["cpath"])), $setEntryPathPerms);
|
|
161 }
|
|
162 }
|
|
163
|
|
164
|
|
165 //
|
|
166 // Main program starts
|
|
167 //
|
|
168 if ($argc < 2)
|
|
169 {
|
|
170 echo
|
|
171 "faptool - Do stuff with FAPWeb database\n".
|
|
172 "(C) Copyright 2014 ccr/TNSP\n".
|
|
173 "\n".
|
|
174 "Usage: ".$argv[0]." <mode> [args]\n".
|
|
175 "Where mode is one of following:\n".
|
|
176 "\n".
|
|
177 " init\n".
|
|
178 " Create directories for entries and previews, if needed.\n".
|
|
179 "\n".
|
881
|
180 " previews <cmd> [args]\n".
|
|
181 " Where <cmd> is one of:\n".
|
|
182 " status - List files and show what is missing, etc.\n".
|
827
|
183 "\n";
|
|
184 exit;
|
|
185 }
|
|
186
|
|
187 // Try to connect to database
|
|
188 $spec = stGetSetting("sqlDB");
|
|
189 if (($db = stConnectSQLDBSpec($spec)) === false)
|
|
190 die("Could not connect to SQL database '".$spec."'.\n");
|
|
191
|
|
192 echo "Using database spec '".$spec."'.\n";
|
|
193
|
|
194 // Fetch non-"hardcoded" settings from SQL database
|
|
195 stReloadSettings();
|
|
196
|
|
197 // Set some globals for our benefit
|
|
198 $setEntryPath = stGetSetting("entryPath");
|
|
199 $setPreviewPath = stGetSetting("previewPath");
|
|
200 $setPreviewURL = stGetSetting("previewURL");
|
|
201 $setThumbDir = stGetSetting("thumbnailSubDir");
|
832
|
202 $setEntryPathPerms = stGetSetting("entryPathPerms");
|
|
203 $setPrevPathPerms = stGetSetting("previewPathPerms");
|
827
|
204
|
|
205 if ($setEntryPath === FALSE || $setPreviewPath === FALSE ||
|
832
|
206 $setPreviewURL === FALSE || $setThumbDir === FALSE ||
|
|
207 $setEntryPathPerms === FALSE || $setPrevPathPerms === FALSE)
|
827
|
208 {
|
831
|
209 die("Some required settings not defined in mconfig.inc.php!\n");
|
827
|
210 }
|
|
211
|
|
212
|
|
213 // Act according to specified command
|
|
214 switch (substr(stCArgLC(1), 0, 4))
|
|
215 {
|
|
216 case "init":
|
|
217 //
|
|
218 // Initialize the data directories etc
|
|
219 //
|
|
220 stInitializeDirs();
|
|
221 break;
|
|
222
|
881
|
223 case "prev":
|
|
224 //
|
|
225 // Preview files handling
|
|
226 //
|
|
227 $mode = substr(stCArgLC(2), 0, 3);
|
|
228 switch ($mode)
|
|
229 {
|
|
230 case "sta":
|
|
231 // List previews that are found and missing
|
|
232 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL") as $compo)
|
|
233 {
|
|
234 printf(
|
|
235 "\n".
|
|
236 "--[ #%03d - %-30s ]---\n".
|
|
237 "PrevType : %s\n".
|
|
238 "PrevPath : %s\n".
|
|
239 "----------------------------------------------\n",
|
|
240 $compo["id"], $compo["name"],
|
|
241 $previewTypeList[$compo["preview_type"]][0],
|
|
242 stMakePath(FALSE, FALSE, array($setPreviewPath, $compo["cpath"])));
|
|
243
|
|
244 foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$compo["id"]) as $entry)
|
|
245 wtHandleEntryPreview($compo, $entry, $mode);
|
|
246 }
|
|
247 break;
|
|
248
|
|
249 default:
|
|
250 if ($mode == "")
|
|
251 die("ERROR! Previews command requires a sub-command argument.\n");
|
|
252 else
|
|
253 die("ERROR! Invalid previews sub-command '".stCArg(2)."'.\n");
|
|
254 break;
|
|
255 }
|
|
256 break;
|
|
257
|
827
|
258 default:
|
|
259 echo "ERROR! Invalid operation mode '".stCArg(1)."'.\n";
|
|
260 break;
|
|
261 }
|
|
262
|
|
263 ?> |