annotate faptool.php @ 880:6db8ef2bb1b5

Changed stMakePath() API.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 26 Nov 2014 16:30:49 +0200
parents bd1cfc7b52d2
children 7c805dccd4f7
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
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 //
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 // Create directories
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 function stMakeDir($path, $perm)
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 {
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 if (!file_exists($path))
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 {
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 echo " - Creating ".$path."\n";
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 if (mkdir($path, $perm, TRUE) === false)
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 die("Could not create directory '".$path."'\n");
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 }
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 }
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 function stInitializeDirs()
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 {
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 global $setEntryPath, $setPreviewPath, $setThumbDir,
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 $setEntryPathPerms, $setPrevPathPerms;
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 echo "Checking for missing directories ...\n";
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 stMakeDir($setEntryPath, $setEntryPathPerms);
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 stMakeDir($setPreviewPath, $setPrevPathPerms);
880
6db8ef2bb1b5 Changed stMakePath() API.
Matti Hamalainen <ccr@tnsp.org>
parents: 832
diff changeset
31 stMakeDir(stMakePath(FALSE, FALSE, array($setPreviewPath, $setThumbDir)), $setPrevPathPerms);
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 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
34 {
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 stMakeDir(stMakePath(FALSE, FALSE, array($setEntryPath, $compo["cpath"])), $setEntryPathPerms);
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 }
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 }
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 //
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 // Main program starts
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 //
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 if ($argc < 2)
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 {
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 echo
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 "faptool - Do stuff with FAPWeb database\n".
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 "(C) Copyright 2014 ccr/TNSP\n".
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 "\n".
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 "Usage: ".$argv[0]." <mode> [args]\n".
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 "Where mode is one of following:\n".
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 "\n".
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 " init\n".
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 " Create directories for entries and previews, if needed.\n".
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 "\n".
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 "\n";
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 exit;
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 }
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 // Try to connect to database
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 $spec = stGetSetting("sqlDB");
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 if (($db = stConnectSQLDBSpec($spec)) === false)
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 die("Could not connect to SQL database '".$spec."'.\n");
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 echo "Using database spec '".$spec."'.\n";
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 // Fetch non-"hardcoded" settings from SQL database
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 stReloadSettings();
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 // Set some globals for our benefit
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 $setEntryPath = stGetSetting("entryPath");
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 $setPreviewPath = stGetSetting("previewPath");
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 $setPreviewURL = stGetSetting("previewURL");
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 $setThumbDir = stGetSetting("thumbnailSubDir");
832
Matti Hamalainen <ccr@tnsp.org>
parents: 831
diff changeset
74 $setEntryPathPerms = stGetSetting("entryPathPerms");
Matti Hamalainen <ccr@tnsp.org>
parents: 831
diff changeset
75 $setPrevPathPerms = stGetSetting("previewPathPerms");
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 if ($setEntryPath === FALSE || $setPreviewPath === FALSE ||
832
Matti Hamalainen <ccr@tnsp.org>
parents: 831
diff changeset
78 $setPreviewURL === FALSE || $setThumbDir === FALSE ||
Matti Hamalainen <ccr@tnsp.org>
parents: 831
diff changeset
79 $setEntryPathPerms === FALSE || $setPrevPathPerms === FALSE)
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 {
831
40546d6f9254 Typofix.
Matti Hamalainen <ccr@tnsp.org>
parents: 827
diff changeset
81 die("Some required settings not defined in mconfig.inc.php!\n");
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 }
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 // Act according to specified command
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 switch (substr(stCArgLC(1), 0, 4))
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 {
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 case "init":
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 //
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 // Initialize the data directories etc
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 //
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 stInitializeDirs();
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 break;
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 default:
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 echo "ERROR! Invalid operation mode '".stCArg(1)."'.\n";
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 break;
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 }
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 ?>