|
007d0a9…
|
drh
|
1 |
/* |
|
c19f34c…
|
drh
|
2 |
** Copyright (c) 2009 D. Richard Hipp |
|
007d0a9…
|
drh
|
3 |
** |
|
007d0a9…
|
drh
|
4 |
** This program is free software; you can redistribute it and/or |
|
c06edd2…
|
drh
|
5 |
** modify it under the terms of the Simplified BSD License (also |
|
c06edd2…
|
drh
|
6 |
** known as the "2-Clause License" or "FreeBSD License".) |
|
106fe61…
|
drh
|
7 |
** |
|
007d0a9…
|
drh
|
8 |
** This program is distributed in the hope that it will be useful, |
|
c06edd2…
|
drh
|
9 |
** but without any warranty; without even the implied warranty of |
|
c06edd2…
|
drh
|
10 |
** merchantability or fitness for a particular purpose. |
|
007d0a9…
|
drh
|
11 |
** |
|
007d0a9…
|
drh
|
12 |
** Author contact information: |
|
007d0a9…
|
drh
|
13 |
** [email protected] |
|
007d0a9…
|
drh
|
14 |
** http://www.hwaci.com/drh/ |
|
007d0a9…
|
drh
|
15 |
** |
|
007d0a9…
|
drh
|
16 |
******************************************************************************* |
|
007d0a9…
|
drh
|
17 |
** |
|
007d0a9…
|
drh
|
18 |
** Implementation of the Setup page for "skins". |
|
007d0a9…
|
drh
|
19 |
*/ |
|
007d0a9…
|
drh
|
20 |
#include "config.h" |
|
c30cd93…
|
jan.nijtmans
|
21 |
#include <assert.h> |
|
007d0a9…
|
drh
|
22 |
#include "skins.h" |
|
106fe61…
|
drh
|
23 |
|
|
106fe61…
|
drh
|
24 |
/* |
|
18d76ff…
|
drh
|
25 |
** SETTING: default-skin width=16 |
|
18d76ff…
|
drh
|
26 |
** |
|
18d76ff…
|
drh
|
27 |
** If the text value if this setting is the name of a built-in skin |
|
18d76ff…
|
drh
|
28 |
** then the named skin becomes the default skin for the repository. |
|
18d76ff…
|
drh
|
29 |
*/ |
|
18d76ff…
|
drh
|
30 |
|
|
18d76ff…
|
drh
|
31 |
/* |
|
007d0a9…
|
drh
|
32 |
** An array of available built-in skins. |
|
96fdf09…
|
drh
|
33 |
** |
|
96fdf09…
|
drh
|
34 |
** To add new built-in skins: |
|
96fdf09…
|
drh
|
35 |
** |
|
96fdf09…
|
drh
|
36 |
** 1. Pick a name for the new skin. (Here we use "xyzzy"). |
|
96fdf09…
|
drh
|
37 |
** |
|
5260fbf…
|
jan.nijtmans
|
38 |
** 2. Install files skins/xyzzy/css.txt, skins/xyzzy/header.txt, |
|
96fdf09…
|
drh
|
39 |
** and skins/xyzzy/footer.txt into the source tree. |
|
96fdf09…
|
drh
|
40 |
** |
|
96fdf09…
|
drh
|
41 |
** 3. Rerun "tclsh makemake.tcl" in the src/ folder in order to |
|
96fdf09…
|
drh
|
42 |
** rebuild the makefiles to reference the new CSS, headers, and footers. |
|
96fdf09…
|
drh
|
43 |
** |
|
96fdf09…
|
drh
|
44 |
** 4. Make an entry in the following array for the new skin. |
|
007d0a9…
|
drh
|
45 |
*/ |
|
007d0a9…
|
drh
|
46 |
static struct BuiltinSkin { |
|
96fdf09…
|
drh
|
47 |
const char *zDesc; /* Description of this skin */ |
|
96fdf09…
|
drh
|
48 |
const char *zLabel; /* The directory under skins/ holding this skin */ |
|
96fdf09…
|
drh
|
49 |
char *zSQL; /* Filled in at run-time with SQL to insert this skin */ |
|
007d0a9…
|
drh
|
50 |
} aBuiltinSkin[] = { |
|
106c090…
|
drh
|
51 |
{ "Default", "default", 0 }, |
|
d8ad5a2…
|
drh
|
52 |
{ "Ardoise", "ardoise", 0 }, |
|
22fb2de…
|
drh
|
53 |
{ "Black & White", "black_and_white", 0 }, |
|
106c090…
|
drh
|
54 |
{ "Blitz", "blitz", 0 }, |
|
1e815c4…
|
drh
|
55 |
{ "Dark Mode", "darkmode", 0 }, |
|
9fdc1aa…
|
drh
|
56 |
{ "Eagle", "eagle", 0 }, |
|
8a1ba49…
|
wyoung
|
57 |
{ "Étienne", "etienne", 0 }, |
|
22fb2de…
|
drh
|
58 |
{ "Khaki", "khaki", 0 }, |
|
d8ad5a2…
|
drh
|
59 |
{ "Original", "original", 0 }, |
|
22fb2de…
|
drh
|
60 |
{ "Plain Gray", "plain_gray", 0 }, |
|
d8ad5a2…
|
drh
|
61 |
{ "Xekri", "xekri", 0 }, |
|
106fe61…
|
drh
|
62 |
}; |
|
106fe61…
|
drh
|
63 |
|
|
106fe61…
|
drh
|
64 |
/* |
|
9c88799…
|
drh
|
65 |
** A skin consists of five "files" named here: |
|
106fe61…
|
drh
|
66 |
*/ |
|
70a94d0…
|
jan.nijtmans
|
67 |
static const char *const azSkinFile[] = { |
|
9c88799…
|
drh
|
68 |
"css", "header", "footer", "details", "js" |
|
9c88799…
|
drh
|
69 |
}; |
|
ed36e2e…
|
drh
|
70 |
|
|
ed36e2e…
|
drh
|
71 |
/* |
|
ed36e2e…
|
drh
|
72 |
** Alternative skins can be specified in the CGI script or by options |
|
ed36e2e…
|
drh
|
73 |
** on the "http", "ui", and "server" commands. The alternative skin |
|
ed36e2e…
|
drh
|
74 |
** name must be one of the aBuiltinSkin[].zLabel names. If there is |
|
ed36e2e…
|
drh
|
75 |
** a match, that alternative is used. |
|
ed36e2e…
|
drh
|
76 |
** |
|
ed36e2e…
|
drh
|
77 |
** The following static variable holds the name of the alternative skin, |
|
ed36e2e…
|
drh
|
78 |
** or NULL if the skin should be as configured. |
|
ed36e2e…
|
drh
|
79 |
*/ |
|
ed36e2e…
|
drh
|
80 |
static struct BuiltinSkin *pAltSkin = 0; |
|
bfd413b…
|
drh
|
81 |
static char *zAltSkinDir = 0; |
|
106fe61…
|
drh
|
82 |
static int iDraftSkin = 0; |
|
816f6c0…
|
stephan
|
83 |
/* |
|
816f6c0…
|
stephan
|
84 |
** Used by skin_use_alternative() to store the current skin rank skin |
|
816f6c0…
|
stephan
|
85 |
** so that the /skins page can, if warranted, warn the user that skin |
|
816f6c0…
|
stephan
|
86 |
** changes won't have any effect. |
|
816f6c0…
|
stephan
|
87 |
*/ |
|
24e015d…
|
drh
|
88 |
static int nSkinRank = 6; |
|
24e015d…
|
drh
|
89 |
|
|
24e015d…
|
drh
|
90 |
/* |
|
24e015d…
|
drh
|
91 |
** How the specific skin being used was chosen |
|
24e015d…
|
drh
|
92 |
*/ |
|
24e015d…
|
drh
|
93 |
#if INTERFACE |
|
24e015d…
|
drh
|
94 |
#define SKIN_FROM_DRAFT 0 /* The "draftN" prefix on the PATH_INFO */ |
|
24e015d…
|
drh
|
95 |
#define SKIN_FROM_CMDLINE 1 /* --skin option to server command-line */ |
|
24e015d…
|
drh
|
96 |
#define SKIN_FROM_CGI 2 /* skin: parameter in CGI script */ |
|
24e015d…
|
drh
|
97 |
#define SKIN_FROM_QPARAM 3 /* skin= query parameter */ |
|
24e015d…
|
drh
|
98 |
#define SKIN_FROM_COOKIE 4 /* skin= from fossil_display_settings cookie*/ |
|
18d76ff…
|
drh
|
99 |
#define SKIN_FROM_SETTING 5 /* Built-in named by "default-skin" setting */ |
|
18d76ff…
|
drh
|
100 |
#define SKIN_FROM_CUSTOM 6 /* Skin values in CONFIG table */ |
|
18d76ff…
|
drh
|
101 |
#define SKIN_FROM_DEFAULT 7 /* The built-in named "default" */ |
|
18d76ff…
|
drh
|
102 |
#define SKIN_FROM_UNKNOWN 8 /* Do not yet know which skin to use */ |
|
24e015d…
|
drh
|
103 |
#endif /* INTERFACE */ |
|
18d76ff…
|
drh
|
104 |
static int iSkinSource = SKIN_FROM_UNKNOWN; |
|
24e015d…
|
drh
|
105 |
|
|
106c090…
|
drh
|
106 |
|
|
106c090…
|
drh
|
107 |
/* |
|
106c090…
|
drh
|
108 |
** Skin details are a set of key/value pairs that define display |
|
106c090…
|
drh
|
109 |
** attributes of the skin that cannot be easily specified using CSS |
|
106c090…
|
drh
|
110 |
** or that need to be known on the server-side. |
|
106c090…
|
drh
|
111 |
** |
|
106c090…
|
drh
|
112 |
** The following array holds the value for all known skin details. |
|
106c090…
|
drh
|
113 |
*/ |
|
106c090…
|
drh
|
114 |
static struct SkinDetail { |
|
106c090…
|
drh
|
115 |
const char *zName; /* Name of the detail */ |
|
5b456cf…
|
jan.nijtmans
|
116 |
const char *zValue; /* Value of the detail */ |
|
106c090…
|
drh
|
117 |
} aSkinDetail[] = { |
|
557f51b…
|
drh
|
118 |
{ "pikchr-background", "" }, |
|
08fe2bd…
|
drh
|
119 |
{ "pikchr-fontscale", "" }, |
|
0853ab7…
|
drh
|
120 |
{ "pikchr-foreground", "" }, |
|
08fe2bd…
|
drh
|
121 |
{ "pikchr-scale", "" }, |
|
0853ab7…
|
drh
|
122 |
{ "timeline-arrowheads", "1" }, |
|
0853ab7…
|
drh
|
123 |
{ "timeline-circle-nodes", "0" }, |
|
0853ab7…
|
drh
|
124 |
{ "timeline-color-graph-lines", "0" }, |
|
0853ab7…
|
drh
|
125 |
{ "white-foreground", "0" }, |
|
106c090…
|
drh
|
126 |
}; |
|
ed36e2e…
|
drh
|
127 |
|
|
ed36e2e…
|
drh
|
128 |
/* |
|
ed36e2e…
|
drh
|
129 |
** Invoke this routine to set the alternative skin. Return NULL if the |
|
ed36e2e…
|
drh
|
130 |
** alternative was successfully installed. Return a string listing all |
|
ed36e2e…
|
drh
|
131 |
** available skins if zName does not match an available skin. Memory |
|
ed36e2e…
|
drh
|
132 |
** for the returned string comes from fossil_malloc() and should be freed |
|
ed36e2e…
|
drh
|
133 |
** by the caller. |
|
bfd413b…
|
drh
|
134 |
** |
|
bfd413b…
|
drh
|
135 |
** If the alternative skin name contains one or more '/' characters, then |
|
bfd413b…
|
drh
|
136 |
** it is assumed to be a directory on disk that holds override css.txt, |
|
bfd413b…
|
drh
|
137 |
** footer.txt, and header.txt. This mode can be used for interactive |
|
bfd413b…
|
drh
|
138 |
** development of new skins. |
|
3339420…
|
drh
|
139 |
** |
|
3339420…
|
drh
|
140 |
** The 2nd parameter is a ranking of how important this alternative |
|
3339420…
|
drh
|
141 |
** skin declaration is, and lower values trump higher ones. If a call |
|
3339420…
|
drh
|
142 |
** to this function passes a higher-valued rank than a previous call, |
|
3339420…
|
drh
|
143 |
** the subsequent call becomes a no-op. Only calls with the same or |
|
3339420…
|
drh
|
144 |
** lower rank (i.e. higher priority) will overwrite a previous |
|
3339420…
|
drh
|
145 |
** setting. This approach is used because the CGI/server-time |
|
3339420…
|
drh
|
146 |
** initialization happens in an order which is incompatible with our |
|
3339420…
|
drh
|
147 |
** preferred ranking, making it otherwise more invasive to tell the |
|
3339420…
|
drh
|
148 |
** internals "the --skin flag ranks higher than a URL parameter" (the |
|
3339420…
|
drh
|
149 |
** former gets initialized before both URL parameters and the /draft |
|
3339420…
|
drh
|
150 |
** path determination). |
|
3339420…
|
drh
|
151 |
** |
|
3339420…
|
drh
|
152 |
** The rankings were initially defined in |
|
3339420…
|
drh
|
153 |
** https://fossil-scm.org/forum/forumpost/caf8c9a8bb |
|
24e015d…
|
drh
|
154 |
** but where subsequently revised: |
|
3339420…
|
drh
|
155 |
** |
|
24e015d…
|
drh
|
156 |
** 0) A skin name matching the glob pattern "draft[1-9]" at the start of |
|
24e015d…
|
drh
|
157 |
** the PATH_INFO. |
|
3339420…
|
drh
|
158 |
** |
|
24e015d…
|
drh
|
159 |
** 1) The --skin flag for commands like "fossil ui", "fossil server", or |
|
24e015d…
|
drh
|
160 |
** "fossil http", or the "skin:" CGI config setting. |
|
3339420…
|
drh
|
161 |
** |
|
3339420…
|
drh
|
162 |
** 2) The "skin" display setting cookie or URL argument, in that |
|
24e015d…
|
drh
|
163 |
** order. If the "skin" URL argument is provided and refers to a legal |
|
24e015d…
|
drh
|
164 |
** skin then that will update the display cookie. If the skin name is |
|
24e015d…
|
drh
|
165 |
** illegal it is silently ignored. |
|
24e015d…
|
drh
|
166 |
** |
|
e2bdc10…
|
danield
|
167 |
** 3) The built-in skin identified by the "default-skin" setting, if such |
|
18d76ff…
|
drh
|
168 |
** a setting exists and matches one of the built-in skin names. |
|
18d76ff…
|
drh
|
169 |
** |
|
18d76ff…
|
drh
|
170 |
** 4) Skin properties (settings "css", "details", "footer", "header", |
|
24e015d…
|
drh
|
171 |
** and "js") from the CONFIG db table |
|
24e015d…
|
drh
|
172 |
** |
|
18d76ff…
|
drh
|
173 |
** 5) The built-in skin named "default" |
|
10dfd9e…
|
stephan
|
174 |
** |
|
24e015d…
|
drh
|
175 |
** The iSource integer privides additional detail about where the skin |
|
10dfd9e…
|
stephan
|
176 |
** |
|
10dfd9e…
|
stephan
|
177 |
** As a special case, a NULL or empty name resets zAltSkinDir and |
|
3339420…
|
drh
|
178 |
** pAltSkin to 0 to indicate that the current config-side skin should |
|
3339420…
|
drh
|
179 |
** be used (rank 3, above), then returns 0. |
|
ed36e2e…
|
drh
|
180 |
*/ |
|
24e015d…
|
drh
|
181 |
char *skin_use_alternative(const char *zName, int rank, int iSource){ |
|
ed36e2e…
|
drh
|
182 |
int i; |
|
bfd413b…
|
drh
|
183 |
Blob err = BLOB_INITIALIZER; |
|
816f6c0…
|
stephan
|
184 |
if(rank > nSkinRank) return 0; |
|
816f6c0…
|
stephan
|
185 |
nSkinRank = rank; |
|
10dfd9e…
|
stephan
|
186 |
if( zName && 1==rank && strchr(zName, '/')!=0 ){ |
|
bfd413b…
|
drh
|
187 |
zAltSkinDir = fossil_strdup(zName); |
|
24e015d…
|
drh
|
188 |
iSkinSource = iSource; |
|
10dfd9e…
|
stephan
|
189 |
return 0; |
|
10dfd9e…
|
stephan
|
190 |
} |
|
10dfd9e…
|
stephan
|
191 |
if( zName && sqlite3_strglob("draft[1-9]", zName)==0 ){ |
|
10dfd9e…
|
stephan
|
192 |
skin_use_draft(zName[5] - '0'); |
|
24e015d…
|
drh
|
193 |
iSkinSource = iSource; |
|
3339420…
|
drh
|
194 |
return 0; |
|
3339420…
|
drh
|
195 |
} |
|
10dfd9e…
|
stephan
|
196 |
if(!zName || !*zName){ |
|
10dfd9e…
|
stephan
|
197 |
pAltSkin = 0; |
|
10dfd9e…
|
stephan
|
198 |
zAltSkinDir = 0; |
|
b828d8f…
|
drh
|
199 |
return 0; |
|
b828d8f…
|
drh
|
200 |
} |
|
b828d8f…
|
drh
|
201 |
if( fossil_strcmp(zName, "custom")==0 ){ |
|
b828d8f…
|
drh
|
202 |
pAltSkin = 0; |
|
b828d8f…
|
drh
|
203 |
zAltSkinDir = 0; |
|
b828d8f…
|
drh
|
204 |
iSkinSource = iSource; |
|
24e015d…
|
drh
|
205 |
return 0; |
|
24e015d…
|
drh
|
206 |
} |
|
3cb9ba4…
|
andygoth
|
207 |
for(i=0; i<count(aBuiltinSkin); i++){ |
|
ed36e2e…
|
drh
|
208 |
if( fossil_strcmp(aBuiltinSkin[i].zLabel, zName)==0 ){ |
|
ed36e2e…
|
drh
|
209 |
pAltSkin = &aBuiltinSkin[i]; |
|
24e015d…
|
drh
|
210 |
iSkinSource = iSource; |
|
ed36e2e…
|
drh
|
211 |
return 0; |
|
ed36e2e…
|
drh
|
212 |
} |
|
ed36e2e…
|
drh
|
213 |
} |
|
bfd413b…
|
drh
|
214 |
blob_appendf(&err, "available skins: %s", aBuiltinSkin[0].zLabel); |
|
3cb9ba4…
|
andygoth
|
215 |
for(i=1; i<count(aBuiltinSkin); i++){ |
|
ed36e2e…
|
drh
|
216 |
blob_append(&err, " ", 1); |
|
ed36e2e…
|
drh
|
217 |
blob_append(&err, aBuiltinSkin[i].zLabel, -1); |
|
ed36e2e…
|
drh
|
218 |
} |
|
ed36e2e…
|
drh
|
219 |
return blob_str(&err); |
|
ed36e2e…
|
drh
|
220 |
} |
|
ed36e2e…
|
drh
|
221 |
|
|
ed36e2e…
|
drh
|
222 |
/* |
|
5ce5ff5…
|
drh
|
223 |
** Look for the --skin command-line option and process it. Or |
|
5ce5ff5…
|
drh
|
224 |
** call fossil_fatal() if an unknown skin is specified. |
|
24e015d…
|
drh
|
225 |
** |
|
24e015d…
|
drh
|
226 |
** This routine is called during command-line parsing for commands |
|
24e015d…
|
drh
|
227 |
** like "fossil ui" and "fossil http". |
|
5ce5ff5…
|
drh
|
228 |
*/ |
|
5ce5ff5…
|
drh
|
229 |
void skin_override(void){ |
|
5ce5ff5…
|
drh
|
230 |
const char *zSkin = find_option("skin",0,1); |
|
5ce5ff5…
|
drh
|
231 |
if( zSkin ){ |
|
24e015d…
|
drh
|
232 |
char *zErr = skin_use_alternative(zSkin, 1, SKIN_FROM_CMDLINE); |
|
bfd413b…
|
drh
|
233 |
if( zErr ) fossil_fatal("%s", zErr); |
|
5ce5ff5…
|
drh
|
234 |
} |
|
bfd413b…
|
drh
|
235 |
} |
|
bfd413b…
|
drh
|
236 |
|
|
bfd413b…
|
drh
|
237 |
/* |
|
106fe61…
|
drh
|
238 |
** Use one of the draft skins. |
|
106fe61…
|
drh
|
239 |
*/ |
|
106fe61…
|
drh
|
240 |
void skin_use_draft(int i){ |
|
106fe61…
|
drh
|
241 |
iDraftSkin = i; |
|
24e015d…
|
drh
|
242 |
iSkinSource = SKIN_FROM_DRAFT; |
|
106fe61…
|
drh
|
243 |
} |
|
106fe61…
|
drh
|
244 |
|
|
106fe61…
|
drh
|
245 |
/* |
|
ed36e2e…
|
drh
|
246 |
** The following routines return the various components of the skin |
|
ed36e2e…
|
drh
|
247 |
** that should be used for the current run. |
|
106fe61…
|
drh
|
248 |
** |
|
9c88799…
|
drh
|
249 |
** zWhat is one of: "css", "header", "footer", "details", "js" |
|
ed36e2e…
|
drh
|
250 |
*/ |
|
ed36e2e…
|
drh
|
251 |
const char *skin_get(const char *zWhat){ |
|
ed36e2e…
|
drh
|
252 |
const char *zOut; |
|
ed36e2e…
|
drh
|
253 |
char *z; |
|
106fe61…
|
drh
|
254 |
if( iDraftSkin ){ |
|
106fe61…
|
drh
|
255 |
z = mprintf("draft%d-%s", iDraftSkin, zWhat); |
|
106fe61…
|
drh
|
256 |
zOut = db_get(z, 0); |
|
106fe61…
|
drh
|
257 |
fossil_free(z); |
|
106fe61…
|
drh
|
258 |
if( zOut ) return zOut; |
|
106fe61…
|
drh
|
259 |
} |
|
bfd413b…
|
drh
|
260 |
if( zAltSkinDir ){ |
|
bfd413b…
|
drh
|
261 |
char *z = mprintf("%s/%s.txt", zAltSkinDir, zWhat); |
|
1772357…
|
drh
|
262 |
if( file_isfile(z, ExtFILE) ){ |
|
bfd413b…
|
drh
|
263 |
Blob x; |
|
1772357…
|
drh
|
264 |
blob_read_from_file(&x, z, ExtFILE); |
|
bfd413b…
|
drh
|
265 |
fossil_free(z); |
|
bfd413b…
|
drh
|
266 |
return blob_str(&x); |
|
bfd413b…
|
drh
|
267 |
} |
|
bfd413b…
|
drh
|
268 |
fossil_free(z); |
|
106fe61…
|
drh
|
269 |
} |
|
18d76ff…
|
drh
|
270 |
if( iSkinSource==SKIN_FROM_UNKNOWN ){ |
|
18d76ff…
|
drh
|
271 |
const char *zDflt = db_get("default-skin", 0); |
|
18d76ff…
|
drh
|
272 |
iSkinSource = SKIN_FROM_DEFAULT; |
|
18d76ff…
|
drh
|
273 |
if( zDflt!=0 ){ |
|
18d76ff…
|
drh
|
274 |
int i; |
|
18d76ff…
|
drh
|
275 |
for(i=0; i<count(aBuiltinSkin); i++){ |
|
18d76ff…
|
drh
|
276 |
if( fossil_strcmp(aBuiltinSkin[i].zLabel, zDflt)==0 ){ |
|
18d76ff…
|
drh
|
277 |
pAltSkin = &aBuiltinSkin[i]; |
|
18d76ff…
|
drh
|
278 |
iSkinSource = SKIN_FROM_SETTING; |
|
18d76ff…
|
drh
|
279 |
break; |
|
18d76ff…
|
drh
|
280 |
} |
|
18d76ff…
|
drh
|
281 |
} |
|
18d76ff…
|
drh
|
282 |
} |
|
18d76ff…
|
drh
|
283 |
} |
|
ed36e2e…
|
drh
|
284 |
if( pAltSkin ){ |
|
ed36e2e…
|
drh
|
285 |
z = mprintf("skins/%s/%s.txt", pAltSkin->zLabel, zWhat); |
|
ed36e2e…
|
drh
|
286 |
zOut = builtin_text(z); |
|
ed36e2e…
|
drh
|
287 |
fossil_free(z); |
|
ed36e2e…
|
drh
|
288 |
}else{ |
|
ed36e2e…
|
drh
|
289 |
zOut = db_get(zWhat, 0); |
|
ed36e2e…
|
drh
|
290 |
if( zOut==0 ){ |
|
ed36e2e…
|
drh
|
291 |
z = mprintf("skins/default/%s.txt", zWhat); |
|
ed36e2e…
|
drh
|
292 |
zOut = builtin_text(z); |
|
ed36e2e…
|
drh
|
293 |
fossil_free(z); |
|
b828d8f…
|
drh
|
294 |
}else if( iSkinSource==SKIN_FROM_DEFAULT ){ |
|
24e015d…
|
drh
|
295 |
iSkinSource = SKIN_FROM_CUSTOM; |
|
ed36e2e…
|
drh
|
296 |
} |
|
ed36e2e…
|
drh
|
297 |
} |
|
ed36e2e…
|
drh
|
298 |
return zOut; |
|
6856177…
|
drh
|
299 |
} |
|
6856177…
|
drh
|
300 |
|
|
6856177…
|
drh
|
301 |
/* |
|
6856177…
|
drh
|
302 |
** Return the command-line option used to set the skin, or return NULL |
|
6856177…
|
drh
|
303 |
** if the default skin is being used. |
|
6856177…
|
drh
|
304 |
*/ |
|
6856177…
|
drh
|
305 |
const char *skin_in_use(void){ |
|
6856177…
|
drh
|
306 |
if( zAltSkinDir ) return zAltSkinDir; |
|
6856177…
|
drh
|
307 |
if( pAltSkin ) return pAltSkin->zLabel; |
|
6856177…
|
drh
|
308 |
return 0; |
|
106c090…
|
drh
|
309 |
} |
|
106c090…
|
drh
|
310 |
|
|
106c090…
|
drh
|
311 |
/* |
|
106c090…
|
drh
|
312 |
** Return a pointer to a SkinDetail element. Return 0 if not found. |
|
106c090…
|
drh
|
313 |
*/ |
|
106c090…
|
drh
|
314 |
static struct SkinDetail *skin_detail_find(const char *zName){ |
|
106c090…
|
drh
|
315 |
int lwr = 0; |
|
3cb9ba4…
|
andygoth
|
316 |
int upr = count(aSkinDetail); |
|
106c090…
|
drh
|
317 |
while( upr>=lwr ){ |
|
106c090…
|
drh
|
318 |
int mid = (upr+lwr)/2; |
|
106c090…
|
drh
|
319 |
int c = fossil_strcmp(aSkinDetail[mid].zName, zName); |
|
106c090…
|
drh
|
320 |
if( c==0 ) return &aSkinDetail[mid]; |
|
106c090…
|
drh
|
321 |
if( c<0 ){ |
|
106c090…
|
drh
|
322 |
lwr = mid+1; |
|
106c090…
|
drh
|
323 |
}else{ |
|
106c090…
|
drh
|
324 |
upr = mid-1; |
|
106c090…
|
drh
|
325 |
} |
|
106c090…
|
drh
|
326 |
} |
|
106c090…
|
drh
|
327 |
return 0; |
|
106c090…
|
drh
|
328 |
} |
|
106c090…
|
drh
|
329 |
|
|
106c090…
|
drh
|
330 |
/* Initialize the aSkinDetail array using the text in the details.txt |
|
106c090…
|
drh
|
331 |
** file. |
|
106c090…
|
drh
|
332 |
*/ |
|
106c090…
|
drh
|
333 |
static void skin_detail_initialize(void){ |
|
106c090…
|
drh
|
334 |
static int isInit = 0; |
|
106c090…
|
drh
|
335 |
char *zDetail; |
|
106c090…
|
drh
|
336 |
Blob detail, line, key, value; |
|
106c090…
|
drh
|
337 |
if( isInit ) return; |
|
106c090…
|
drh
|
338 |
isInit = 1; |
|
106c090…
|
drh
|
339 |
zDetail = (char*)skin_get("details"); |
|
106c090…
|
drh
|
340 |
if( zDetail==0 ) return; |
|
106c090…
|
drh
|
341 |
zDetail = fossil_strdup(zDetail); |
|
106c090…
|
drh
|
342 |
blob_init(&detail, zDetail, -1); |
|
106c090…
|
drh
|
343 |
while( blob_line(&detail, &line) ){ |
|
106c090…
|
drh
|
344 |
char *zKey; |
|
106c090…
|
drh
|
345 |
int nKey; |
|
106c090…
|
drh
|
346 |
struct SkinDetail *pDetail; |
|
106c090…
|
drh
|
347 |
if( !blob_token(&line, &key) ) continue; |
|
106c090…
|
drh
|
348 |
zKey = blob_buffer(&key); |
|
106c090…
|
drh
|
349 |
if( zKey[0]=='#' ) continue; |
|
106c090…
|
drh
|
350 |
nKey = blob_size(&key); |
|
106c090…
|
drh
|
351 |
if( nKey<2 ) continue; |
|
106c090…
|
drh
|
352 |
if( zKey[nKey-1]!=':' ) continue; |
|
106c090…
|
drh
|
353 |
zKey[nKey-1] = 0; |
|
106c090…
|
drh
|
354 |
pDetail = skin_detail_find(zKey); |
|
106c090…
|
drh
|
355 |
if( pDetail==0 ) continue; |
|
106c090…
|
drh
|
356 |
if( !blob_token(&line, &value) ) continue; |
|
106c090…
|
drh
|
357 |
pDetail->zValue = fossil_strdup(blob_str(&value)); |
|
106c090…
|
drh
|
358 |
} |
|
106c090…
|
drh
|
359 |
blob_reset(&detail); |
|
106c090…
|
drh
|
360 |
fossil_free(zDetail); |
|
106c090…
|
drh
|
361 |
} |
|
106c090…
|
drh
|
362 |
|
|
106c090…
|
drh
|
363 |
/* |
|
106c090…
|
drh
|
364 |
** Return a skin detail setting |
|
106c090…
|
drh
|
365 |
*/ |
|
106c090…
|
drh
|
366 |
const char *skin_detail(const char *zName){ |
|
106c090…
|
drh
|
367 |
struct SkinDetail *pDetail; |
|
106c090…
|
drh
|
368 |
skin_detail_initialize(); |
|
106c090…
|
drh
|
369 |
pDetail = skin_detail_find(zName); |
|
99fcc43…
|
drh
|
370 |
if( pDetail==0 ) fossil_fatal("no such skin detail: %s", zName); |
|
106c090…
|
drh
|
371 |
return pDetail->zValue; |
|
106c090…
|
drh
|
372 |
} |
|
106c090…
|
drh
|
373 |
int skin_detail_boolean(const char *zName){ |
|
106c090…
|
drh
|
374 |
return !is_false(skin_detail(zName)); |
|
39f084c…
|
drh
|
375 |
} |
|
39f084c…
|
drh
|
376 |
|
|
39f084c…
|
drh
|
377 |
/* |
|
39f084c…
|
drh
|
378 |
** Hash function for computing a skin id. |
|
39f084c…
|
drh
|
379 |
*/ |
|
39f084c…
|
drh
|
380 |
static unsigned int skin_hash(unsigned int h, const char *z){ |
|
39f084c…
|
drh
|
381 |
if( z==0 ) return h; |
|
39f084c…
|
drh
|
382 |
while( z[0] ){ |
|
39f084c…
|
drh
|
383 |
h = (h<<11) ^ (h<<1) ^ (h>>3) ^ z[0]; |
|
39f084c…
|
drh
|
384 |
z++; |
|
39f084c…
|
drh
|
385 |
} |
|
39f084c…
|
drh
|
386 |
return h; |
|
39f084c…
|
drh
|
387 |
} |
|
39f084c…
|
drh
|
388 |
|
|
39f084c…
|
drh
|
389 |
/* |
|
39f084c…
|
drh
|
390 |
** Return an identifier that is (probably) different for every skin |
|
39f084c…
|
drh
|
391 |
** but that is (probably) the same if the skin is unchanged. This |
|
39f084c…
|
drh
|
392 |
** identifier can be attached to resource URLs to force reloading when |
|
39f084c…
|
drh
|
393 |
** the resources change but allow the resources to be read from cache |
|
39f084c…
|
drh
|
394 |
** as long as they are unchanged. |
|
56ad554…
|
drh
|
395 |
** |
|
56ad554…
|
drh
|
396 |
** The zResource argument is the name of a CONFIG setting that |
|
3cbf02a…
|
drh
|
397 |
** defines the resource. Examples: "css", "logo-image". |
|
39f084c…
|
drh
|
398 |
*/ |
|
39f084c…
|
drh
|
399 |
unsigned int skin_id(const char *zResource){ |
|
39f084c…
|
drh
|
400 |
unsigned int h = 0; |
|
39f084c…
|
drh
|
401 |
if( zAltSkinDir ){ |
|
39f084c…
|
drh
|
402 |
h = skin_hash(0, zAltSkinDir); |
|
39f084c…
|
drh
|
403 |
}else if( pAltSkin ){ |
|
39f084c…
|
drh
|
404 |
h = skin_hash(0, pAltSkin->zLabel); |
|
ed36e2e…
|
drh
|
405 |
}else{ |
|
5b456cf…
|
jan.nijtmans
|
406 |
char *zMTime = db_get_mtime(zResource, 0, 0); |
|
39f084c…
|
drh
|
407 |
h = skin_hash(0, zMTime); |
|
39f084c…
|
drh
|
408 |
fossil_free(zMTime); |
|
ed36e2e…
|
drh
|
409 |
} |
|
3cbf02a…
|
drh
|
410 |
|
|
3cbf02a…
|
drh
|
411 |
/* Change the ID every time Fossil is recompiled */ |
|
56ad554…
|
drh
|
412 |
h = skin_hash(h, fossil_exe_id()); |
|
39f084c…
|
drh
|
413 |
return h; |
|
ed36e2e…
|
drh
|
414 |
} |
|
007d0a9…
|
drh
|
415 |
|
|
007d0a9…
|
drh
|
416 |
/* |
|
007d0a9…
|
drh
|
417 |
** For a skin named zSkinName, compute the name of the CONFIG table |
|
007d0a9…
|
drh
|
418 |
** entry where that skin is stored and return it. |
|
007d0a9…
|
drh
|
419 |
** |
|
007d0a9…
|
drh
|
420 |
** Return NULL if zSkinName is NULL or an empty string. |
|
007d0a9…
|
drh
|
421 |
** |
|
007d0a9…
|
drh
|
422 |
** If ifExists is true, and the named skin does not exist, return NULL. |
|
007d0a9…
|
drh
|
423 |
*/ |
|
007d0a9…
|
drh
|
424 |
static char *skinVarName(const char *zSkinName, int ifExists){ |
|
007d0a9…
|
drh
|
425 |
char *z; |
|
007d0a9…
|
drh
|
426 |
if( zSkinName==0 || zSkinName[0]==0 ) return 0; |
|
007d0a9…
|
drh
|
427 |
z = mprintf("skin:%s", zSkinName); |
|
007d0a9…
|
drh
|
428 |
if( ifExists && !db_exists("SELECT 1 FROM config WHERE name=%Q", z) ){ |
|
007d0a9…
|
drh
|
429 |
free(z); |
|
007d0a9…
|
drh
|
430 |
z = 0; |
|
007d0a9…
|
drh
|
431 |
} |
|
007d0a9…
|
drh
|
432 |
return z; |
|
007d0a9…
|
drh
|
433 |
} |
|
007d0a9…
|
drh
|
434 |
|
|
007d0a9…
|
drh
|
435 |
/* |
|
e5a4206…
|
drh
|
436 |
** Return true if there exists a skin name "zSkinName". |
|
e5a4206…
|
drh
|
437 |
*/ |
|
e5a4206…
|
drh
|
438 |
static int skinExists(const char *zSkinName){ |
|
e5a4206…
|
drh
|
439 |
int i; |
|
e5a4206…
|
drh
|
440 |
if( zSkinName==0 ) return 0; |
|
3cb9ba4…
|
andygoth
|
441 |
for(i=0; i<count(aBuiltinSkin); i++){ |
|
e5a4206…
|
drh
|
442 |
if( fossil_strcmp(zSkinName, aBuiltinSkin[i].zDesc)==0 ) return 1; |
|
e5a4206…
|
drh
|
443 |
} |
|
e5a4206…
|
drh
|
444 |
return db_exists("SELECT 1 FROM config WHERE name='skin:%q'", zSkinName); |
|
e5a4206…
|
drh
|
445 |
} |
|
e5a4206…
|
drh
|
446 |
|
|
e5a4206…
|
drh
|
447 |
/* |
|
96fdf09…
|
drh
|
448 |
** Construct and return an string of SQL statements that represents |
|
96fdf09…
|
drh
|
449 |
** a "skin" setting. If zName==0 then return the skin currently |
|
96fdf09…
|
drh
|
450 |
** installed. Otherwise, return one of the built-in skins designated |
|
96fdf09…
|
drh
|
451 |
** by zName. |
|
007d0a9…
|
drh
|
452 |
** |
|
007d0a9…
|
drh
|
453 |
** Memory to hold the returned string is obtained from malloc. |
|
007d0a9…
|
drh
|
454 |
*/ |
|
96fdf09…
|
drh
|
455 |
static char *getSkin(const char *zName){ |
|
96fdf09…
|
drh
|
456 |
const char *z; |
|
96fdf09…
|
drh
|
457 |
char *zLabel; |
|
96fdf09…
|
drh
|
458 |
int i; |
|
007d0a9…
|
drh
|
459 |
Blob val; |
|
007d0a9…
|
drh
|
460 |
blob_zero(&val); |
|
106fe61…
|
drh
|
461 |
for(i=0; i<count(azSkinFile); i++){ |
|
96fdf09…
|
drh
|
462 |
if( zName ){ |
|
106fe61…
|
drh
|
463 |
zLabel = mprintf("skins/%s/%s.txt", zName, azSkinFile[i]); |
|
96fdf09…
|
drh
|
464 |
z = builtin_text(zLabel); |
|
96fdf09…
|
drh
|
465 |
fossil_free(zLabel); |
|
96fdf09…
|
drh
|
466 |
}else{ |
|
106fe61…
|
drh
|
467 |
z = db_get(azSkinFile[i], 0); |
|
96fdf09…
|
drh
|
468 |
if( z==0 ){ |
|
106fe61…
|
drh
|
469 |
zLabel = mprintf("skins/default/%s.txt", azSkinFile[i]); |
|
96fdf09…
|
drh
|
470 |
z = builtin_text(zLabel); |
|
96fdf09…
|
drh
|
471 |
fossil_free(zLabel); |
|
96fdf09…
|
drh
|
472 |
} |
|
96fdf09…
|
drh
|
473 |
} |
|
f741baa…
|
drh
|
474 |
db_unprotect(PROTECT_CONFIG); |
|
96fdf09…
|
drh
|
475 |
blob_appendf(&val, |
|
96fdf09…
|
drh
|
476 |
"REPLACE INTO config(name,value,mtime) VALUES(%Q,%Q,now());\n", |
|
106fe61…
|
drh
|
477 |
azSkinFile[i], z |
|
96fdf09…
|
drh
|
478 |
); |
|
f741baa…
|
drh
|
479 |
db_protect_pop(); |
|
96fdf09…
|
drh
|
480 |
} |
|
007d0a9…
|
drh
|
481 |
return blob_str(&val); |
|
007d0a9…
|
drh
|
482 |
} |
|
007d0a9…
|
drh
|
483 |
|
|
007d0a9…
|
drh
|
484 |
/* |
|
2431ddf…
|
drh
|
485 |
** Respond to a Rename button press. Return TRUE if a dialog was painted. |
|
2431ddf…
|
drh
|
486 |
** Return FALSE to continue with the main Skins page. |
|
2431ddf…
|
drh
|
487 |
*/ |
|
2431ddf…
|
drh
|
488 |
static int skinRename(void){ |
|
2431ddf…
|
drh
|
489 |
const char *zOldName; |
|
2431ddf…
|
drh
|
490 |
const char *zNewName; |
|
e5a4206…
|
drh
|
491 |
int ex = 0; |
|
2431ddf…
|
drh
|
492 |
if( P("rename")==0 ) return 0; |
|
2431ddf…
|
drh
|
493 |
zOldName = P("sn"); |
|
2431ddf…
|
drh
|
494 |
zNewName = P("newname"); |
|
2431ddf…
|
drh
|
495 |
if( zOldName==0 ) return 0; |
|
e5a4206…
|
drh
|
496 |
if( zNewName==0 || zNewName[0]==0 || (ex = skinExists(zNewName))!=0 ){ |
|
e5a4206…
|
drh
|
497 |
if( zNewName==0 ) zNewName = zOldName; |
|
112c713…
|
drh
|
498 |
style_set_current_feature("skins"); |
|
2431ddf…
|
drh
|
499 |
style_header("Rename A Skin"); |
|
e5a4206…
|
drh
|
500 |
if( ex ){ |
|
e5a4206…
|
drh
|
501 |
@ <p><span class="generalError">There is already another skin |
|
e5a4206…
|
drh
|
502 |
@ named "%h(zNewName)". Choose a different name.</span></p> |
|
e5a4206…
|
drh
|
503 |
} |
|
a40e8a0…
|
drh
|
504 |
@ <form action="%R/setup_skin_admin" method="post"><div> |
|
2431ddf…
|
drh
|
505 |
@ <table border="0"><tr> |
|
2431ddf…
|
drh
|
506 |
@ <tr><td align="right">Current name:<td align="left"><b>%h(zOldName)</b> |
|
2431ddf…
|
drh
|
507 |
@ <tr><td align="right">New name:<td align="left"> |
|
e5a4206…
|
drh
|
508 |
@ <input type="text" size="35" name="newname" value="%h(zNewName)"> |
|
2431ddf…
|
drh
|
509 |
@ <tr><td><td> |
|
2431ddf…
|
drh
|
510 |
@ <input type="hidden" name="sn" value="%h(zOldName)"> |
|
2431ddf…
|
drh
|
511 |
@ <input type="submit" name="rename" value="Rename"> |
|
2431ddf…
|
drh
|
512 |
@ <input type="submit" name="canren" value="Cancel"> |
|
2431ddf…
|
drh
|
513 |
@ </table> |
|
2431ddf…
|
drh
|
514 |
login_insert_csrf_secret(); |
|
2431ddf…
|
drh
|
515 |
@ </div></form> |
|
112c713…
|
drh
|
516 |
style_finish_page(); |
|
2431ddf…
|
drh
|
517 |
return 1; |
|
2431ddf…
|
drh
|
518 |
} |
|
f741baa…
|
drh
|
519 |
db_unprotect(PROTECT_CONFIG); |
|
2431ddf…
|
drh
|
520 |
db_multi_exec( |
|
2431ddf…
|
drh
|
521 |
"UPDATE config SET name='skin:%q' WHERE name='skin:%q';", |
|
2431ddf…
|
drh
|
522 |
zNewName, zOldName |
|
2431ddf…
|
drh
|
523 |
); |
|
f741baa…
|
drh
|
524 |
db_protect_pop(); |
|
e5a4206…
|
drh
|
525 |
return 0; |
|
e5a4206…
|
drh
|
526 |
} |
|
e5a4206…
|
drh
|
527 |
|
|
e5a4206…
|
drh
|
528 |
/* |
|
e5a4206…
|
drh
|
529 |
** Respond to a Save button press. Return TRUE if a dialog was painted. |
|
e5a4206…
|
drh
|
530 |
** Return FALSE to continue with the main Skins page. |
|
e5a4206…
|
drh
|
531 |
*/ |
|
e5a4206…
|
drh
|
532 |
static int skinSave(const char *zCurrent){ |
|
e5a4206…
|
drh
|
533 |
const char *zNewName; |
|
e5a4206…
|
drh
|
534 |
int ex = 0; |
|
e5a4206…
|
drh
|
535 |
if( P("save")==0 ) return 0; |
|
e5a4206…
|
drh
|
536 |
zNewName = P("svname"); |
|
e5a4206…
|
drh
|
537 |
if( zNewName && zNewName[0]!=0 ){ |
|
e5a4206…
|
drh
|
538 |
} |
|
e5a4206…
|
drh
|
539 |
if( zNewName==0 || zNewName[0]==0 || (ex = skinExists(zNewName))!=0 ){ |
|
e5a4206…
|
drh
|
540 |
if( zNewName==0 ) zNewName = ""; |
|
112c713…
|
drh
|
541 |
style_set_current_feature("skins"); |
|
e5a4206…
|
drh
|
542 |
style_header("Save Current Skin"); |
|
e5a4206…
|
drh
|
543 |
if( ex ){ |
|
e5a4206…
|
drh
|
544 |
@ <p><span class="generalError">There is already another skin |
|
e5a4206…
|
drh
|
545 |
@ named "%h(zNewName)". Choose a different name.</span></p> |
|
e5a4206…
|
drh
|
546 |
} |
|
a40e8a0…
|
drh
|
547 |
@ <form action="%R/setup_skin_admin" method="post"><div> |
|
e5a4206…
|
drh
|
548 |
@ <table border="0"><tr> |
|
e5a4206…
|
drh
|
549 |
@ <tr><td align="right">Name for this skin:<td align="left"> |
|
e5a4206…
|
drh
|
550 |
@ <input type="text" size="35" name="svname" value="%h(zNewName)"> |
|
e5a4206…
|
drh
|
551 |
@ <tr><td><td> |
|
e5a4206…
|
drh
|
552 |
@ <input type="submit" name="save" value="Save"> |
|
e5a4206…
|
drh
|
553 |
@ <input type="submit" name="cansave" value="Cancel"> |
|
e5a4206…
|
drh
|
554 |
@ </table> |
|
e5a4206…
|
drh
|
555 |
login_insert_csrf_secret(); |
|
e5a4206…
|
drh
|
556 |
@ </div></form> |
|
112c713…
|
drh
|
557 |
style_finish_page(); |
|
e5a4206…
|
drh
|
558 |
return 1; |
|
e5a4206…
|
drh
|
559 |
} |
|
f741baa…
|
drh
|
560 |
db_unprotect(PROTECT_CONFIG); |
|
e5a4206…
|
drh
|
561 |
db_multi_exec( |
|
e5a4206…
|
drh
|
562 |
"INSERT OR IGNORE INTO config(name, value, mtime)" |
|
e5a4206…
|
drh
|
563 |
"VALUES('skin:%q',%Q,now())", |
|
e5a4206…
|
drh
|
564 |
zNewName, zCurrent |
|
e5a4206…
|
drh
|
565 |
); |
|
f741baa…
|
drh
|
566 |
db_protect_pop(); |
|
2431ddf…
|
drh
|
567 |
return 0; |
|
2431ddf…
|
drh
|
568 |
} |
|
112c713…
|
drh
|
569 |
|
|
112c713…
|
drh
|
570 |
/* |
|
f3702b8…
|
drh
|
571 |
** Return true if a custom skin exists |
|
f3702b8…
|
drh
|
572 |
*/ |
|
f3702b8…
|
drh
|
573 |
static int skin_exists_custom(void){ |
|
f3702b8…
|
drh
|
574 |
return db_exists("SELECT 1 FROM config WHERE name IN" |
|
f3702b8…
|
drh
|
575 |
" ('css','details','footer','header','js')"); |
|
f3702b8…
|
drh
|
576 |
} |
|
f3702b8…
|
drh
|
577 |
|
|
f3702b8…
|
drh
|
578 |
static void skin_publish(int); /* Forward reference */ |
|
f3702b8…
|
drh
|
579 |
|
|
f3702b8…
|
drh
|
580 |
/* |
|
106fe61…
|
drh
|
581 |
** WEBPAGE: setup_skin_admin |
|
7ab0328…
|
drh
|
582 |
** |
|
106fe61…
|
drh
|
583 |
** Administrative actions on skins. For administrators only. |
|
d8bbe4a…
|
drh
|
584 |
*/ |
|
106fe61…
|
drh
|
585 |
void setup_skin_admin(void){ |
|
d8bbe4a…
|
drh
|
586 |
const char *z; |
|
d8bbe4a…
|
drh
|
587 |
char *zName; |
|
d8bbe4a…
|
drh
|
588 |
char *zErr = 0; |
|
96fdf09…
|
drh
|
589 |
const char *zCurrent = 0; /* Current skin */ |
|
96fdf09…
|
drh
|
590 |
int i; /* Loop counter */ |
|
d8bbe4a…
|
drh
|
591 |
Stmt q; |
|
106fe61…
|
drh
|
592 |
int once; |
|
33cc83f…
|
drh
|
593 |
const char *zOverride = 0; |
|
f3702b8…
|
drh
|
594 |
const char *zDfltSkin = 0; |
|
f3702b8…
|
drh
|
595 |
int seenDefault = 0; |
|
f3702b8…
|
drh
|
596 |
int hasCustom; |
|
d8bbe4a…
|
drh
|
597 |
|
|
d8bbe4a…
|
drh
|
598 |
login_check_credentials(); |
|
7b58c6f…
|
wyoung
|
599 |
if( !g.perm.Admin ){ |
|
653dd40…
|
drh
|
600 |
login_needed(0); |
|
653dd40…
|
drh
|
601 |
return; |
|
d8bbe4a…
|
drh
|
602 |
} |
|
e1962ef…
|
drh
|
603 |
db_begin_transaction(); |
|
96fdf09…
|
drh
|
604 |
zCurrent = getSkin(0); |
|
3cb9ba4…
|
andygoth
|
605 |
for(i=0; i<count(aBuiltinSkin); i++){ |
|
96fdf09…
|
drh
|
606 |
aBuiltinSkin[i].zSQL = getSkin(aBuiltinSkin[i].zLabel); |
|
96fdf09…
|
drh
|
607 |
} |
|
96fdf09…
|
drh
|
608 |
|
|
112c713…
|
drh
|
609 |
style_set_current_feature("skins"); |
|
112c713…
|
drh
|
610 |
|
|
920ace1…
|
drh
|
611 |
if( cgi_csrf_safe(2) ){ |
|
c9efdfc…
|
drh
|
612 |
/* Process requests to delete a user-defined skin */ |
|
f3702b8…
|
drh
|
613 |
if( P("del1") && P("sn")!=0 ){ |
|
c9efdfc…
|
drh
|
614 |
style_header("Confirm Custom Skin Delete"); |
|
a40e8a0…
|
drh
|
615 |
@ <form action="%R/setup_skin_admin" method="post"><div> |
|
c9efdfc…
|
drh
|
616 |
@ <p>Deletion of a custom skin is a permanent action that cannot |
|
c9efdfc…
|
drh
|
617 |
@ be undone. Please confirm that this is what you want to do:</p> |
|
f5482a0…
|
wyoung
|
618 |
@ <input type="hidden" name="sn" value="%h(P("sn"))"> |
|
f5482a0…
|
wyoung
|
619 |
@ <input type="submit" name="del2" value="Confirm - Delete The Skin"> |
|
f5482a0…
|
wyoung
|
620 |
@ <input type="submit" name="cancel" value="Cancel - Do Not Delete"> |
|
c9efdfc…
|
drh
|
621 |
login_insert_csrf_secret(); |
|
c9efdfc…
|
drh
|
622 |
@ </div></form> |
|
112c713…
|
drh
|
623 |
style_finish_page(); |
|
1c0b78b…
|
wyoung
|
624 |
db_end_transaction(1); |
|
c9efdfc…
|
drh
|
625 |
return; |
|
c9efdfc…
|
drh
|
626 |
} |
|
f3702b8…
|
drh
|
627 |
if( P("del2")!=0 ){ |
|
f741baa…
|
drh
|
628 |
db_unprotect(PROTECT_CONFIG); |
|
f3702b8…
|
drh
|
629 |
if( fossil_strcmp(P("sn"),"custom")==0 ){ |
|
f3702b8…
|
drh
|
630 |
db_multi_exec("DELETE FROM config WHERE name IN" |
|
f3702b8…
|
drh
|
631 |
"('css','details','footer','header','js')"); |
|
f3702b8…
|
drh
|
632 |
}else if( (zName = skinVarName(P("sn"), 1))!=0 ){ |
|
f3702b8…
|
drh
|
633 |
db_multi_exec("DELETE FROM config WHERE name=%Q", zName); |
|
f3702b8…
|
drh
|
634 |
} |
|
f741baa…
|
drh
|
635 |
db_protect_pop(); |
|
c9efdfc…
|
drh
|
636 |
} |
|
c9efdfc…
|
drh
|
637 |
if( P("draftdel")!=0 ){ |
|
c9efdfc…
|
drh
|
638 |
const char *zDraft = P("name"); |
|
c9efdfc…
|
drh
|
639 |
if( sqlite3_strglob("draft[1-9]",zDraft)==0 ){ |
|
f741baa…
|
drh
|
640 |
db_unprotect(PROTECT_CONFIG); |
|
c9efdfc…
|
drh
|
641 |
db_multi_exec("DELETE FROM config WHERE name GLOB '%q-*'", zDraft); |
|
f741baa…
|
drh
|
642 |
db_protect_pop(); |
|
1c0b78b…
|
wyoung
|
643 |
} |
|
f741baa…
|
drh
|
644 |
} |
|
33cc83f…
|
drh
|
645 |
if( P("editdraft")!=0 ){ |
|
33cc83f…
|
drh
|
646 |
db_end_transaction(0); |
|
33cc83f…
|
drh
|
647 |
cgi_redirectf("%R/setup_skin"); |
|
33cc83f…
|
drh
|
648 |
return; |
|
33cc83f…
|
drh
|
649 |
} |
|
1c0b78b…
|
wyoung
|
650 |
if( skinRename() || skinSave(zCurrent) ){ |
|
1c0b78b…
|
wyoung
|
651 |
db_end_transaction(0); |
|
33cc83f…
|
drh
|
652 |
return; |
|
33cc83f…
|
drh
|
653 |
} |
|
33cc83f…
|
drh
|
654 |
|
|
f3702b8…
|
drh
|
655 |
if( P("setdflt") && (z = P("bisl"))!=0 ){ |
|
f3702b8…
|
drh
|
656 |
if( z[0] ){ |
|
f3702b8…
|
drh
|
657 |
db_set("default-skin", z, 0); |
|
f3702b8…
|
drh
|
658 |
}else{ |
|
f3702b8…
|
drh
|
659 |
db_unset("default-skin", 0); |
|
f3702b8…
|
drh
|
660 |
} |
|
f3702b8…
|
drh
|
661 |
db_end_transaction(0); |
|
f3702b8…
|
drh
|
662 |
cgi_redirectf("%R/setup_skin_admin"); |
|
f3702b8…
|
drh
|
663 |
return; |
|
f3702b8…
|
drh
|
664 |
} |
|
f3702b8…
|
drh
|
665 |
|
|
c9efdfc…
|
drh
|
666 |
/* The user pressed one of the "Install" buttons. */ |
|
c9efdfc…
|
drh
|
667 |
if( P("load") && (z = P("sn"))!=0 && z[0] ){ |
|
c9efdfc…
|
drh
|
668 |
int seen = 0; |
|
70a94d0…
|
jan.nijtmans
|
669 |
|
|
c9efdfc…
|
drh
|
670 |
/* Check to see if the current skin is already saved. If it is, there |
|
c9efdfc…
|
drh
|
671 |
** is no need to create a backup */ |
|
f3702b8…
|
drh
|
672 |
hasCustom = skin_exists_custom(); |
|
f3702b8…
|
drh
|
673 |
if( hasCustom ){ |
|
f3702b8…
|
drh
|
674 |
zCurrent = getSkin(0); |
|
f3702b8…
|
drh
|
675 |
for(i=0; i<count(aBuiltinSkin); i++){ |
|
f3702b8…
|
drh
|
676 |
if( fossil_strcmp(aBuiltinSkin[i].zSQL, zCurrent)==0 ){ |
|
f3702b8…
|
drh
|
677 |
seen = 1; |
|
f3702b8…
|
drh
|
678 |
break; |
|
f3702b8…
|
drh
|
679 |
} |
|
f3702b8…
|
drh
|
680 |
} |
|
f3702b8…
|
drh
|
681 |
if( !seen ){ |
|
f3702b8…
|
drh
|
682 |
seen = db_exists("SELECT 1 FROM config WHERE name GLOB 'skin:*'" |
|
f3702b8…
|
drh
|
683 |
" AND value=%Q", zCurrent); |
|
f3702b8…
|
drh
|
684 |
if( !seen ){ |
|
f3702b8…
|
drh
|
685 |
db_unprotect(PROTECT_CONFIG); |
|
f3702b8…
|
drh
|
686 |
db_multi_exec( |
|
f3702b8…
|
drh
|
687 |
"INSERT INTO config(name,value,mtime) VALUES(" |
|
f3702b8…
|
drh
|
688 |
" strftime('skin:Backup On %%Y-%%m-%%d %%H:%%M:%%S')," |
|
f3702b8…
|
drh
|
689 |
" %Q,now())", zCurrent |
|
f3702b8…
|
drh
|
690 |
); |
|
f3702b8…
|
drh
|
691 |
db_protect_pop(); |
|
f3702b8…
|
drh
|
692 |
} |
|
c9efdfc…
|
drh
|
693 |
} |
|
c9efdfc…
|
drh
|
694 |
} |
|
c9efdfc…
|
drh
|
695 |
seen = 0; |
|
f3702b8…
|
drh
|
696 |
if( z[0]>='1' && z[0]<='9' && z[1]==0 ){ |
|
f3702b8…
|
drh
|
697 |
skin_publish(z[0]-'0'); |
|
f3702b8…
|
drh
|
698 |
seen = 1; |
|
f3702b8…
|
drh
|
699 |
} |
|
f3702b8…
|
drh
|
700 |
for(i=0; seen==0 && i<count(aBuiltinSkin); i++){ |
|
c9efdfc…
|
drh
|
701 |
if( fossil_strcmp(aBuiltinSkin[i].zDesc, z)==0 ){ |
|
c9efdfc…
|
drh
|
702 |
seen = 1; |
|
c9efdfc…
|
drh
|
703 |
zCurrent = aBuiltinSkin[i].zSQL; |
|
37c2905…
|
stephan
|
704 |
db_unprotect(PROTECT_CONFIG); |
|
c9efdfc…
|
drh
|
705 |
db_multi_exec("%s", zCurrent/*safe-for-%s*/); |
|
37c2905…
|
stephan
|
706 |
db_protect_pop(); |
|
c9efdfc…
|
drh
|
707 |
break; |
|
c9efdfc…
|
drh
|
708 |
} |
|
c9efdfc…
|
drh
|
709 |
} |
|
c9efdfc…
|
drh
|
710 |
if( !seen ){ |
|
c9efdfc…
|
drh
|
711 |
zName = skinVarName(z,0); |
|
c9efdfc…
|
drh
|
712 |
zCurrent = db_get(zName, 0); |
|
37c2905…
|
stephan
|
713 |
db_unprotect(PROTECT_CONFIG); |
|
c9efdfc…
|
drh
|
714 |
db_multi_exec("%s", zCurrent/*safe-for-%s*/); |
|
37c2905…
|
stephan
|
715 |
db_protect_pop(); |
|
c9efdfc…
|
drh
|
716 |
} |
|
c9efdfc…
|
drh
|
717 |
} |
|
37c2905…
|
stephan
|
718 |
} |
|
37c2905…
|
stephan
|
719 |
|
|
f3702b8…
|
drh
|
720 |
zDfltSkin = db_get("default-skin",0); |
|
f3702b8…
|
drh
|
721 |
hasCustom = skin_exists_custom(); |
|
f3702b8…
|
drh
|
722 |
if( !hasCustom && zDfltSkin==0 ){ |
|
f3702b8…
|
drh
|
723 |
zDfltSkin = "default"; |
|
f3702b8…
|
drh
|
724 |
} |
|
f3702b8…
|
drh
|
725 |
|
|
d8bbe4a…
|
drh
|
726 |
style_header("Skins"); |
|
d8bbe4a…
|
drh
|
727 |
if( zErr ){ |
|
d1f60ca…
|
jan.nijtmans
|
728 |
@ <p style="color:red">%h(zErr)</p> |
|
d1f60ca…
|
jan.nijtmans
|
729 |
} |
|
2431ddf…
|
drh
|
730 |
@ <table border="0"> |
|
f3702b8…
|
drh
|
731 |
@ <tr><td colspan=4><h2>Built-in Skins:</h2></td></tr> |
|
3cb9ba4…
|
andygoth
|
732 |
for(i=0; i<count(aBuiltinSkin); i++){ |
|
2431ddf…
|
drh
|
733 |
z = aBuiltinSkin[i].zDesc; |
|
2431ddf…
|
drh
|
734 |
@ <tr><td>%d(i+1).<td>%h(z)<td> <td> |
|
f3702b8…
|
drh
|
735 |
@ <form action="%R/setup_skin_admin" method="POST"> |
|
f3702b8…
|
drh
|
736 |
login_insert_csrf_secret(); |
|
f3702b8…
|
drh
|
737 |
if( zDfltSkin==0 || fossil_strcmp(aBuiltinSkin[i].zLabel, zDfltSkin)!=0 ){ |
|
f3702b8…
|
drh
|
738 |
/* vvvv--- mnemonic: Built-In Skin Label */ |
|
f3702b8…
|
drh
|
739 |
@ <input type="hidden" name="bisl" value="%h(aBuiltinSkin[i].zLabel)"> |
|
f3702b8…
|
drh
|
740 |
@ <input type="submit" name="setdflt" value="Set"> |
|
2431ddf…
|
drh
|
741 |
}else{ |
|
f3702b8…
|
drh
|
742 |
@ (Selected) |
|
f3702b8…
|
drh
|
743 |
seenDefault = 1; |
|
f3702b8…
|
drh
|
744 |
} |
|
f3702b8…
|
drh
|
745 |
if( pAltSkin==&aBuiltinSkin[i] && iSkinSource!=SKIN_FROM_SETTING ){ |
|
f3702b8…
|
drh
|
746 |
@ (Override) |
|
99575d4…
|
drh
|
747 |
zOverride = z; |
|
f3702b8…
|
drh
|
748 |
} |
|
f3702b8…
|
drh
|
749 |
@ </form></td></tr> |
|
33cc83f…
|
drh
|
750 |
} |
|
33cc83f…
|
drh
|
751 |
if( zOverride ){ |
|
33cc83f…
|
drh
|
752 |
@ <tr><td> <td colspan="3"> |
|
33cc83f…
|
drh
|
753 |
@ <p>Note: Built-in skin "%h(zOverride)" is currently being used because of |
|
33cc83f…
|
drh
|
754 |
switch( iSkinSource ){ |
|
33cc83f…
|
drh
|
755 |
case SKIN_FROM_CMDLINE: |
|
33cc83f…
|
drh
|
756 |
@ the --skin command-line option. |
|
33cc83f…
|
drh
|
757 |
break; |
|
33cc83f…
|
drh
|
758 |
case SKIN_FROM_CGI: |
|
33cc83f…
|
drh
|
759 |
@ the "skin:" option on CGI script. |
|
33cc83f…
|
drh
|
760 |
break; |
|
33cc83f…
|
drh
|
761 |
case SKIN_FROM_QPARAM: |
|
33cc83f…
|
drh
|
762 |
@ the "skin=NAME" query parameter. |
|
33cc83f…
|
drh
|
763 |
break; |
|
33cc83f…
|
drh
|
764 |
case SKIN_FROM_COOKIE: |
|
33cc83f…
|
drh
|
765 |
@ the "skin" value of the |
|
33cc83f…
|
drh
|
766 |
@ <a href='./fdscookie'>fossil_display_setting</a> cookie. |
|
33cc83f…
|
drh
|
767 |
break; |
|
18d76ff…
|
drh
|
768 |
case SKIN_FROM_SETTING: |
|
18d76ff…
|
drh
|
769 |
@ the "default-skin" setting. |
|
18d76ff…
|
drh
|
770 |
break; |
|
33cc83f…
|
drh
|
771 |
default: |
|
33cc83f…
|
drh
|
772 |
@ reasons unknown. (Fix me!) |
|
33cc83f…
|
drh
|
773 |
break; |
|
2431ddf…
|
drh
|
774 |
} |
|
2431ddf…
|
drh
|
775 |
@ </tr> |
|
2431ddf…
|
drh
|
776 |
} |
|
f3702b8…
|
drh
|
777 |
i++; |
|
f3702b8…
|
drh
|
778 |
@ <tr><td colspan=4><h2>Custom skin:</h2></td></tr> |
|
f3702b8…
|
drh
|
779 |
@ <tr><td>%d(i). |
|
f3702b8…
|
drh
|
780 |
if( hasCustom ){ |
|
f3702b8…
|
drh
|
781 |
@ <td>Custom<td> <td> |
|
f3702b8…
|
drh
|
782 |
}else{ |
|
f3702b8…
|
drh
|
783 |
@ <td><i>(None)</i><td> <td> |
|
f3702b8…
|
drh
|
784 |
} |
|
f3702b8…
|
drh
|
785 |
@ <form method="post"> |
|
f3702b8…
|
drh
|
786 |
login_insert_csrf_secret(); |
|
f3702b8…
|
drh
|
787 |
if( hasCustom ){ |
|
f3702b8…
|
drh
|
788 |
@ <input type="submit" name="save" value="Backup"> |
|
f3702b8…
|
drh
|
789 |
@ <input type="submit" name="editdraft" value="Edit"> |
|
f3702b8…
|
drh
|
790 |
if( !seenDefault ){ |
|
f3702b8…
|
drh
|
791 |
@ (Selected) |
|
f3702b8…
|
drh
|
792 |
}else{ |
|
f3702b8…
|
drh
|
793 |
@ <input type="hidden" name="bisl" value=""> |
|
f3702b8…
|
drh
|
794 |
@ <input type="submit" name="setdflt" value="Set"> |
|
f3702b8…
|
drh
|
795 |
@ <input type="submit" name="del1" value="Delete"> |
|
f3702b8…
|
drh
|
796 |
@ <input type="hidden" name="sn" value="custom"> |
|
f3702b8…
|
drh
|
797 |
} |
|
f3702b8…
|
drh
|
798 |
}else{ |
|
f3702b8…
|
drh
|
799 |
@ <input type="submit" name="editdraft" value="Create"> |
|
f3702b8…
|
drh
|
800 |
} |
|
f3702b8…
|
drh
|
801 |
@ </form> |
|
f3702b8…
|
drh
|
802 |
@ </td></tr> |
|
2431ddf…
|
drh
|
803 |
db_prepare(&q, |
|
f3702b8…
|
drh
|
804 |
"SELECT substr(name, 6) FROM config" |
|
2431ddf…
|
drh
|
805 |
" WHERE name GLOB 'skin:*'" |
|
2431ddf…
|
drh
|
806 |
" ORDER BY name" |
|
2431ddf…
|
drh
|
807 |
); |
|
106fe61…
|
drh
|
808 |
once = 1; |
|
2431ddf…
|
drh
|
809 |
while( db_step(&q)==SQLITE_ROW ){ |
|
2431ddf…
|
drh
|
810 |
const char *zN = db_column_text(&q, 0); |
|
2431ddf…
|
drh
|
811 |
i++; |
|
106fe61…
|
drh
|
812 |
if( once ){ |
|
106fe61…
|
drh
|
813 |
once = 0; |
|
f3702b8…
|
drh
|
814 |
@ <tr><td colspan=4><h2>Backups of past custom skins:</h2></td></tr> |
|
106fe61…
|
drh
|
815 |
} |
|
2431ddf…
|
drh
|
816 |
@ <tr><td>%d(i).<td>%h(zN)<td> <td> |
|
a40e8a0…
|
drh
|
817 |
@ <form action="%R/setup_skin_admin" method="post"> |
|
920ace1…
|
drh
|
818 |
login_insert_csrf_secret(); |
|
f3702b8…
|
drh
|
819 |
@ <input type="submit" name="load" value="Install"> |
|
f3702b8…
|
drh
|
820 |
@ <input type="submit" name="del1" value="Delete"> |
|
2431ddf…
|
drh
|
821 |
@ <input type="submit" name="rename" value="Rename"> |
|
2431ddf…
|
drh
|
822 |
@ <input type="hidden" name="sn" value="%h(zN)"> |
|
2431ddf…
|
drh
|
823 |
@ </form></tr> |
|
2431ddf…
|
drh
|
824 |
} |
|
2431ddf…
|
drh
|
825 |
db_finalize(&q); |
|
106fe61…
|
drh
|
826 |
db_prepare(&q, |
|
106fe61…
|
drh
|
827 |
"SELECT DISTINCT substr(name, 1, 6) FROM config" |
|
106fe61…
|
drh
|
828 |
" WHERE name GLOB 'draft[1-9]-*'" |
|
106fe61…
|
drh
|
829 |
" ORDER BY name" |
|
106fe61…
|
drh
|
830 |
); |
|
106fe61…
|
drh
|
831 |
once = 1; |
|
106fe61…
|
drh
|
832 |
while( db_step(&q)==SQLITE_ROW ){ |
|
106fe61…
|
drh
|
833 |
const char *zN = db_column_text(&q, 0); |
|
e5a4206…
|
drh
|
834 |
i++; |
|
106fe61…
|
drh
|
835 |
if( once ){ |
|
106fe61…
|
drh
|
836 |
once = 0; |
|
f3702b8…
|
drh
|
837 |
@ <tr><td colspan=4><h2>Draft skins:</h2></td></tr> |
|
106fe61…
|
drh
|
838 |
} |
|
106fe61…
|
drh
|
839 |
@ <tr><td>%d(i).<td>%h(zN)<td> <td> |
|
a40e8a0…
|
drh
|
840 |
@ <form action="%R/setup_skin_admin" method="post"> |
|
920ace1…
|
drh
|
841 |
login_insert_csrf_secret(); |
|
f3702b8…
|
drh
|
842 |
@ <input type="submit" name="load" value="Install"> |
|
106fe61…
|
drh
|
843 |
@ <input type="submit" name="draftdel" value="Delete"> |
|
106fe61…
|
drh
|
844 |
@ <input type="hidden" name="name" value="%h(zN)"> |
|
f3702b8…
|
drh
|
845 |
@ <input type="hidden" name="sn" value="%h(zN+5)"> |
|
106fe61…
|
drh
|
846 |
@ </form></tr> |
|
106c090…
|
drh
|
847 |
} |
|
106fe61…
|
drh
|
848 |
db_finalize(&q); |
|
106fe61…
|
drh
|
849 |
|
|
106c090…
|
drh
|
850 |
@ </table> |
|
112c713…
|
drh
|
851 |
style_finish_page(); |
|
106c090…
|
drh
|
852 |
db_end_transaction(0); |
|
106c090…
|
drh
|
853 |
} |
|
c6ee75a…
|
drh
|
854 |
|
|
c6ee75a…
|
drh
|
855 |
/* |
|
c6ee75a…
|
drh
|
856 |
** Generate HTML for a <select> that lists all the available skin names, |
|
c6ee75a…
|
drh
|
857 |
** except for zExcept if zExcept!=NULL. |
|
c6ee75a…
|
drh
|
858 |
*/ |
|
c6ee75a…
|
drh
|
859 |
static void skin_emit_skin_selector( |
|
c6ee75a…
|
drh
|
860 |
const char *zVarName, /* Variable name for the <select> */ |
|
c6ee75a…
|
drh
|
861 |
const char *zDefault, /* The default value, if not NULL */ |
|
c6ee75a…
|
drh
|
862 |
const char *zExcept /* Omit this skin if not NULL */ |
|
c6ee75a…
|
drh
|
863 |
){ |
|
c6ee75a…
|
drh
|
864 |
int i; |
|
f3702b8…
|
drh
|
865 |
Stmt s; |
|
c6ee75a…
|
drh
|
866 |
@ <select size='1' name='%s(zVarName)'> |
|
f3702b8…
|
drh
|
867 |
if( fossil_strcmp(zExcept, "current")!=0 && skin_exists_custom() ){ |
|
f3702b8…
|
drh
|
868 |
@ <option value='current'>Current Custom Skin</option> |
|
c6ee75a…
|
drh
|
869 |
} |
|
c6ee75a…
|
drh
|
870 |
for(i=0; i<count(aBuiltinSkin); i++){ |
|
c6ee75a…
|
drh
|
871 |
const char *zName = aBuiltinSkin[i].zLabel; |
|
c6ee75a…
|
drh
|
872 |
if( fossil_strcmp(zName, zExcept)==0 ) continue; |
|
c6ee75a…
|
drh
|
873 |
if( fossil_strcmp(zDefault, zName)==0 ){ |
|
c6ee75a…
|
drh
|
874 |
@ <option value='%s(zName)' selected>\ |
|
f3702b8…
|
drh
|
875 |
@ %h(aBuiltinSkin[i].zDesc)</option> |
|
c6ee75a…
|
drh
|
876 |
}else{ |
|
c6ee75a…
|
drh
|
877 |
@ <option value='%s(zName)'>\ |
|
f3702b8…
|
drh
|
878 |
@ %h(aBuiltinSkin[i].zDesc)</option> |
|
c6ee75a…
|
drh
|
879 |
} |
|
c6ee75a…
|
drh
|
880 |
} |
|
f3702b8…
|
drh
|
881 |
db_prepare(&s, "SELECT DISTINCT substr(name,1,6) FROM config" |
|
f3702b8…
|
drh
|
882 |
" WHERE name GLOB 'draft[1-9]-*' ORDER BY 1"); |
|
f3702b8…
|
drh
|
883 |
while( db_step(&s)==SQLITE_ROW ){ |
|
f3702b8…
|
drh
|
884 |
const char *zName = db_column_text(&s, 0); |
|
c6ee75a…
|
drh
|
885 |
if( fossil_strcmp(zName, zExcept)==0 ) continue; |
|
c6ee75a…
|
drh
|
886 |
if( fossil_strcmp(zDefault, zName)==0 ){ |
|
c6ee75a…
|
drh
|
887 |
@ <option value='%s(zName)' selected>%s(zName)</option> |
|
c6ee75a…
|
drh
|
888 |
}else{ |
|
c6ee75a…
|
drh
|
889 |
@ <option value='%s(zName)'>%s(zName)</option> |
|
c6ee75a…
|
drh
|
890 |
} |
|
c6ee75a…
|
drh
|
891 |
} |
|
f3702b8…
|
drh
|
892 |
db_finalize(&s); |
|
c6ee75a…
|
drh
|
893 |
@ </select> |
|
c6ee75a…
|
drh
|
894 |
} |
|
c6ee75a…
|
drh
|
895 |
|
|
c6ee75a…
|
drh
|
896 |
/* |
|
c6ee75a…
|
drh
|
897 |
** Return the text of one of the skin files. |
|
c6ee75a…
|
drh
|
898 |
*/ |
|
c6ee75a…
|
drh
|
899 |
static const char *skin_file_content(const char *zLabel, const char *zFile){ |
|
c6ee75a…
|
drh
|
900 |
const char *zResult; |
|
c6ee75a…
|
drh
|
901 |
if( fossil_strcmp(zLabel, "current")==0 ){ |
|
5c90832…
|
drh
|
902 |
zResult = skin_get(zFile); |
|
c6ee75a…
|
drh
|
903 |
}else if( sqlite3_strglob("draft[1-9]", zLabel)==0 ){ |
|
2fac7df…
|
drh
|
904 |
zResult = db_get_mprintf("", "%s-%s", zLabel, zFile); |
|
c6ee75a…
|
drh
|
905 |
}else{ |
|
995e184…
|
drh
|
906 |
int i; |
|
995e184…
|
drh
|
907 |
for(i=0; i<2; i++){ |
|
c6ee75a…
|
drh
|
908 |
char *zKey = mprintf("skins/%s/%s.txt", zLabel, zFile); |
|
c6ee75a…
|
drh
|
909 |
zResult = builtin_text(zKey); |
|
c6ee75a…
|
drh
|
910 |
fossil_free(zKey); |
|
995e184…
|
drh
|
911 |
if( zResult!=0 ) break; |
|
995e184…
|
drh
|
912 |
zLabel = "default"; |
|
c6ee75a…
|
drh
|
913 |
} |
|
c6ee75a…
|
drh
|
914 |
} |
|
c6ee75a…
|
drh
|
915 |
return zResult; |
|
c6ee75a…
|
drh
|
916 |
} |
|
c6ee75a…
|
drh
|
917 |
|
|
a8967ca…
|
drh
|
918 |
extern const struct strctCssDefaults { |
|
a8967ca…
|
drh
|
919 |
/* From the generated default_css.h, which we cannot #include here |
|
a8967ca…
|
drh
|
920 |
** without causing an ODR violation. |
|
a8967ca…
|
drh
|
921 |
*/ |
|
a8967ca…
|
drh
|
922 |
const char *elementClass; /* Name of element needed */ |
|
a8967ca…
|
drh
|
923 |
const char *value; /* CSS text */ |
|
a8967ca…
|
drh
|
924 |
} cssDefaultList[]; |
|
106c090…
|
drh
|
925 |
|
|
106c090…
|
drh
|
926 |
/* |
|
106c090…
|
drh
|
927 |
** WEBPAGE: setup_skinedit |
|
106c090…
|
drh
|
928 |
** |
|
7ab0328…
|
drh
|
929 |
** Edit aspects of a skin determined by the w= query parameter. |
|
7b58c6f…
|
wyoung
|
930 |
** Requires Admin or Setup privileges. |
|
7ab0328…
|
drh
|
931 |
** |
|
9c88799…
|
drh
|
932 |
** w=NUM -- 0=CSS, 1=footer, 2=header, 3=details, 4=js |
|
106fe61…
|
drh
|
933 |
** sk=NUM -- the draft skin number |
|
106c090…
|
drh
|
934 |
*/ |
|
106c090…
|
drh
|
935 |
void setup_skinedit(void){ |
|
106c090…
|
drh
|
936 |
static const struct sSkinAddr { |
|
106c090…
|
drh
|
937 |
const char *zFile; |
|
106c090…
|
drh
|
938 |
const char *zTitle; |
|
106c090…
|
drh
|
939 |
const char *zSubmenu; |
|
106c090…
|
drh
|
940 |
} aSkinAttr[] = { |
|
106c090…
|
drh
|
941 |
/* 0 */ { "css", "CSS", "CSS", }, |
|
106c090…
|
drh
|
942 |
/* 1 */ { "footer", "Page Footer", "Footer", }, |
|
106c090…
|
drh
|
943 |
/* 2 */ { "header", "Page Header", "Header", }, |
|
106c090…
|
drh
|
944 |
/* 3 */ { "details", "Display Details", "Details", }, |
|
9c88799…
|
drh
|
945 |
/* 4 */ { "js", "JavaScript", "Script", }, |
|
106c090…
|
drh
|
946 |
}; |
|
c6ee75a…
|
drh
|
947 |
const char *zBasis; /* The baseline file */ |
|
bd2bf81…
|
drh
|
948 |
const char *zOrig; /* Original content prior to editing */ |
|
c6ee75a…
|
drh
|
949 |
const char *zContent; /* Content after editing */ |
|
bd2bf81…
|
drh
|
950 |
const char *zDflt; /* Default content */ |
|
c6ee75a…
|
drh
|
951 |
char *zDraft; /* Which draft: "draft%d" */ |
|
c6ee75a…
|
drh
|
952 |
char *zTitle; /* Title of this page */ |
|
c6ee75a…
|
drh
|
953 |
const char *zFile; /* One of "css", "footer", "header", "details" */ |
|
c6ee75a…
|
drh
|
954 |
int iSkin; /* draft number. 1..9 */ |
|
c6ee75a…
|
drh
|
955 |
int ii; /* Index in aSkinAttr[] of this file */ |
|
c6ee75a…
|
drh
|
956 |
int j; /* Loop counter */ |
|
bd2bf81…
|
drh
|
957 |
int isRevert = 0; /* True if Revert-to-Baseline was pressed */ |
|
106c090…
|
drh
|
958 |
|
|
106c090…
|
drh
|
959 |
login_check_credentials(); |
|
106fe61…
|
drh
|
960 |
|
|
106fe61…
|
drh
|
961 |
/* Figure out which skin we are editing */ |
|
106fe61…
|
drh
|
962 |
iSkin = atoi(PD("sk","1")); |
|
106fe61…
|
drh
|
963 |
if( iSkin<1 || iSkin>9 ) iSkin = 1; |
|
106fe61…
|
drh
|
964 |
|
|
106fe61…
|
drh
|
965 |
/* Check that the user is authorized to edit this skin. */ |
|
7b58c6f…
|
wyoung
|
966 |
if( !g.perm.Admin ){ |
|
a2e1f9f…
|
drh
|
967 |
char *zAllowedEditors = ""; |
|
106fe61…
|
drh
|
968 |
Glob *pAllowedEditors; |
|
09e6fc3…
|
drh
|
969 |
int isMatch = 0; |
|
a2e1f9f…
|
drh
|
970 |
if( login_is_individual() ){ |
|
a2e1f9f…
|
drh
|
971 |
zAllowedEditors = db_get_mprintf("", "draft%d-users", iSkin); |
|
a2e1f9f…
|
drh
|
972 |
} |
|
106fe61…
|
drh
|
973 |
if( zAllowedEditors[0] ){ |
|
106fe61…
|
drh
|
974 |
pAllowedEditors = glob_create(zAllowedEditors); |
|
a2e1f9f…
|
drh
|
975 |
isMatch = glob_match(pAllowedEditors, g.zLogin); |
|
106fe61…
|
drh
|
976 |
glob_free(pAllowedEditors); |
|
09e6fc3…
|
drh
|
977 |
} |
|
09e6fc3…
|
drh
|
978 |
if( isMatch==0 ){ |
|
09e6fc3…
|
drh
|
979 |
login_needed(0); |
|
09e6fc3…
|
drh
|
980 |
return; |
|
106fe61…
|
drh
|
981 |
} |
|
106c090…
|
drh
|
982 |
} |
|
106fe61…
|
drh
|
983 |
|
|
106fe61…
|
drh
|
984 |
/* figure out which file is to be edited */ |
|
106c090…
|
drh
|
985 |
ii = atoi(PD("w","0")); |
|
3cb9ba4…
|
andygoth
|
986 |
if( ii<0 || ii>count(aSkinAttr) ) ii = 0; |
|
c6ee75a…
|
drh
|
987 |
zFile = aSkinAttr[ii].zFile; |
|
c6ee75a…
|
drh
|
988 |
zDraft = mprintf("draft%d", iSkin); |
|
106fe61…
|
drh
|
989 |
zTitle = mprintf("%s for Draft%d", aSkinAttr[ii].zTitle, iSkin); |
|
c6ee75a…
|
drh
|
990 |
zBasis = PD("basis","current"); |
|
bd2bf81…
|
drh
|
991 |
zDflt = skin_file_content(zBasis, zFile); |
|
0a5d0e1…
|
drh
|
992 |
zOrig = db_get_mprintf(zDflt, "draft%d-%s",iSkin,zFile); |
|
bd2bf81…
|
drh
|
993 |
zContent = PD(zFile,zOrig); |
|
920ace1…
|
drh
|
994 |
if( P("revert")!=0 && cgi_csrf_safe(2) ){ |
|
bd2bf81…
|
drh
|
995 |
zContent = zDflt; |
|
bd2bf81…
|
drh
|
996 |
isRevert = 1; |
|
bd2bf81…
|
drh
|
997 |
} |
|
106fe61…
|
drh
|
998 |
|
|
e1962ef…
|
drh
|
999 |
db_begin_transaction(); |
|
112c713…
|
drh
|
1000 |
style_set_current_feature("skins"); |
|
106fe61…
|
drh
|
1001 |
style_header("%s", zTitle); |
|
3cb9ba4…
|
andygoth
|
1002 |
for(j=0; j<count(aSkinAttr); j++){ |
|
187424e…
|
andygoth
|
1003 |
style_submenu_element(aSkinAttr[j].zSubmenu, |
|
106fe61…
|
drh
|
1004 |
"%R/setup_skinedit?w=%d&basis=%h&sk=%d",j,zBasis,iSkin); |
|
187424e…
|
andygoth
|
1005 |
} |
|
a40e8a0…
|
drh
|
1006 |
@ <form action="%R/setup_skinedit" method="post"><div> |
|
106c090…
|
drh
|
1007 |
login_insert_csrf_secret(); |
|
106c090…
|
drh
|
1008 |
@ <input type='hidden' name='w' value='%d(ii)'> |
|
106fe61…
|
drh
|
1009 |
@ <input type='hidden' name='sk' value='%d(iSkin)'> |
|
106fe61…
|
drh
|
1010 |
@ <h2>Edit %s(zTitle):</h2> |
|
920ace1…
|
drh
|
1011 |
if( P("submit") && cgi_csrf_safe(2) |
|
920ace1…
|
drh
|
1012 |
&& (zOrig==0 || strcmp(zOrig,zContent)!=0) |
|
920ace1…
|
drh
|
1013 |
){ |
|
0a5d0e1…
|
drh
|
1014 |
db_set_mprintf(zContent, 0, "draft%d-%s",iSkin,zFile); |
|
bd2bf81…
|
drh
|
1015 |
} |
|
bd2bf81…
|
drh
|
1016 |
@ <textarea name="%s(zFile)" rows="10" cols="80">\ |
|
bd2bf81…
|
drh
|
1017 |
@ %h(zContent)</textarea> |
|
f5482a0…
|
wyoung
|
1018 |
@ <br> |
|
f5482a0…
|
wyoung
|
1019 |
@ <input type="submit" name="submit" value="Apply Changes"> |
|
bd2bf81…
|
drh
|
1020 |
if( isRevert ){ |
|
bd2bf81…
|
drh
|
1021 |
@ ← Press to complete reversion to "%s(zBasis)" |
|
bd2bf81…
|
drh
|
1022 |
}else if( fossil_strcmp(zContent,zDflt)!=0 ){ |
|
f5482a0…
|
wyoung
|
1023 |
@ <input type="submit" name="revert" value='Revert To "%s(zBasis)"'> |
|
bd2bf81…
|
drh
|
1024 |
} |
|
f5482a0…
|
wyoung
|
1025 |
@ <hr> |
|
c6ee75a…
|
drh
|
1026 |
@ Baseline: \ |
|
c6ee75a…
|
drh
|
1027 |
skin_emit_skin_selector("basis", zBasis, zDraft); |
|
f5482a0…
|
wyoung
|
1028 |
@ <input type="submit" name="diff" value="Unified Diff"> |
|
f5482a0…
|
wyoung
|
1029 |
@ <input type="submit" name="sbsdiff" value="Side-by-Side Diff"> |
|
523c548…
|
drh
|
1030 |
if( P("diff")!=0 || P("sbsdiff")!=0 ){ |
|
106c090…
|
drh
|
1031 |
Blob from, to, out; |
|
1347a1d…
|
drh
|
1032 |
DiffConfig DCfg; |
|
1347a1d…
|
drh
|
1033 |
construct_diff_flags(1, &DCfg); |
|
1347a1d…
|
drh
|
1034 |
DCfg.diffFlags |= DIFF_STRIP_EOLCR; |
|
1347a1d…
|
drh
|
1035 |
if( P("sbsdiff")!=0 ) DCfg.diffFlags |= DIFF_SIDEBYSIDE; |
|
106c090…
|
drh
|
1036 |
blob_init(&to, zContent, -1); |
|
c6ee75a…
|
drh
|
1037 |
blob_init(&from, skin_file_content(zBasis, zFile), -1); |
|
106c090…
|
drh
|
1038 |
blob_zero(&out); |
|
275da70…
|
danield
|
1039 |
DCfg.diffFlags |= DIFF_HTML | DIFF_NOTTOOBIG; |
|
1347a1d…
|
drh
|
1040 |
if( DCfg.diffFlags & DIFF_SIDEBYSIDE ){ |
|
1347a1d…
|
drh
|
1041 |
text_diff(&from, &to, &out, &DCfg); |
|
106c090…
|
drh
|
1042 |
@ %s(blob_str(&out)) |
|
106c090…
|
drh
|
1043 |
}else{ |
|
1347a1d…
|
drh
|
1044 |
DCfg.diffFlags |= DIFF_LINENO; |
|
1347a1d…
|
drh
|
1045 |
text_diff(&from, &to, &out, &DCfg); |
|
106c090…
|
drh
|
1046 |
@ <pre class="udiff"> |
|
106c090…
|
drh
|
1047 |
@ %s(blob_str(&out)) |
|
106c090…
|
drh
|
1048 |
@ </pre> |
|
106c090…
|
drh
|
1049 |
} |
|
106c090…
|
drh
|
1050 |
blob_reset(&from); |
|
106c090…
|
drh
|
1051 |
blob_reset(&to); |
|
106c090…
|
drh
|
1052 |
blob_reset(&out); |
|
106c090…
|
drh
|
1053 |
} |
|
106c090…
|
drh
|
1054 |
@ </div></form> |
|
112c713…
|
drh
|
1055 |
style_finish_page(); |
|
106c090…
|
drh
|
1056 |
db_end_transaction(0); |
|
106fe61…
|
drh
|
1057 |
} |
|
106fe61…
|
drh
|
1058 |
|
|
106fe61…
|
drh
|
1059 |
/* |
|
106fe61…
|
drh
|
1060 |
** Try to initialize draft skin iSkin to the built-in or preexisting |
|
106fe61…
|
drh
|
1061 |
** skin named by zTemplate. |
|
106fe61…
|
drh
|
1062 |
*/ |
|
106fe61…
|
drh
|
1063 |
static void skin_initialize_draft(int iSkin, const char *zTemplate){ |
|
106fe61…
|
drh
|
1064 |
int i; |
|
106fe61…
|
drh
|
1065 |
if( zTemplate==0 ) return; |
|
c6ee75a…
|
drh
|
1066 |
for(i=0; i<count(azSkinFile); i++){ |
|
c6ee75a…
|
drh
|
1067 |
const char *z = skin_file_content(zTemplate, azSkinFile[i]); |
|
2fac7df…
|
drh
|
1068 |
db_set_mprintf(z, 0, "draft%d-%s", iSkin, azSkinFile[i]); |
|
106fe61…
|
drh
|
1069 |
} |
|
106fe61…
|
drh
|
1070 |
} |
|
106fe61…
|
drh
|
1071 |
|
|
106fe61…
|
drh
|
1072 |
/* |
|
106fe61…
|
drh
|
1073 |
** Publish the draft skin iSkin as the new default. |
|
106fe61…
|
drh
|
1074 |
*/ |
|
106fe61…
|
drh
|
1075 |
static void skin_publish(int iSkin){ |
|
106fe61…
|
drh
|
1076 |
char *zCurrent; /* SQL description of the current skin */ |
|
106fe61…
|
drh
|
1077 |
char *zBuiltin; /* SQL description of a built-in skin */ |
|
106fe61…
|
drh
|
1078 |
int i; |
|
106fe61…
|
drh
|
1079 |
int seen = 0; /* True if no need to make a backup */ |
|
106fe61…
|
drh
|
1080 |
|
|
106fe61…
|
drh
|
1081 |
/* Check to see if the current skin is already saved. If it is, there |
|
106fe61…
|
drh
|
1082 |
** is no need to create a backup */ |
|
106fe61…
|
drh
|
1083 |
zCurrent = getSkin(0); |
|
106fe61…
|
drh
|
1084 |
for(i=0; i<count(aBuiltinSkin); i++){ |
|
106fe61…
|
drh
|
1085 |
zBuiltin = getSkin(aBuiltinSkin[i].zLabel); |
|
205a748…
|
drh
|
1086 |
if( fossil_strcmp(zBuiltin, zCurrent)==0 ){ |
|
106fe61…
|
drh
|
1087 |
seen = 1; |
|
106fe61…
|
drh
|
1088 |
break; |
|
106fe61…
|
drh
|
1089 |
} |
|
106fe61…
|
drh
|
1090 |
} |
|
106fe61…
|
drh
|
1091 |
if( !seen ){ |
|
106fe61…
|
drh
|
1092 |
seen = db_exists("SELECT 1 FROM config WHERE name GLOB 'skin:*'" |
|
106fe61…
|
drh
|
1093 |
" AND value=%Q", zCurrent); |
|
106fe61…
|
drh
|
1094 |
} |
|
106fe61…
|
drh
|
1095 |
if( !seen ){ |
|
f741baa…
|
drh
|
1096 |
db_unprotect(PROTECT_CONFIG); |
|
106fe61…
|
drh
|
1097 |
db_multi_exec( |
|
106fe61…
|
drh
|
1098 |
"INSERT INTO config(name,value,mtime) VALUES(" |
|
106fe61…
|
drh
|
1099 |
" strftime('skin:Backup On %%Y-%%m-%%d %%H:%%M:%%S')," |
|
106fe61…
|
drh
|
1100 |
" %Q,now())", zCurrent |
|
106fe61…
|
drh
|
1101 |
); |
|
f741baa…
|
drh
|
1102 |
db_protect_pop(); |
|
106fe61…
|
drh
|
1103 |
} |
|
106fe61…
|
drh
|
1104 |
|
|
106fe61…
|
drh
|
1105 |
/* Publish draft iSkin */ |
|
106fe61…
|
drh
|
1106 |
for(i=0; i<count(azSkinFile); i++){ |
|
2fac7df…
|
drh
|
1107 |
char *zNew = db_get_mprintf("", "draft%d-%s", iSkin, azSkinFile[i]); |
|
0a5d0e1…
|
drh
|
1108 |
db_set(azSkinFile[i]/*works-like:"x"*/, zNew, 0); |
|
106fe61…
|
drh
|
1109 |
} |
|
f3702b8…
|
drh
|
1110 |
db_unset("default-skin", 0); |
|
106fe61…
|
drh
|
1111 |
} |
|
106fe61…
|
drh
|
1112 |
|
|
106fe61…
|
drh
|
1113 |
/* |
|
106fe61…
|
drh
|
1114 |
** WEBPAGE: setup_skin |
|
106fe61…
|
drh
|
1115 |
** |
|
f3702b8…
|
drh
|
1116 |
** Generate a page showing the steps needed to create or edit |
|
f3702b8…
|
drh
|
1117 |
** a custom skin. |
|
106fe61…
|
drh
|
1118 |
*/ |
|
106fe61…
|
drh
|
1119 |
void setup_skin(void){ |
|
106fe61…
|
drh
|
1120 |
int i; /* Loop counter */ |
|
106fe61…
|
drh
|
1121 |
int iSkin; /* Which draft skin is being edited */ |
|
106fe61…
|
drh
|
1122 |
int isSetup; /* True for an administrator */ |
|
106fe61…
|
drh
|
1123 |
int isEditor; /* Others authorized to make edits */ |
|
106fe61…
|
drh
|
1124 |
char *zAllowedEditors; /* Who may edit the draft skin */ |
|
106fe61…
|
drh
|
1125 |
char *zBase; /* Base URL for draft under test */ |
|
70a94d0…
|
jan.nijtmans
|
1126 |
static const char *const azTestPages[] = { |
|
106fe61…
|
drh
|
1127 |
"home", |
|
106fe61…
|
drh
|
1128 |
"timeline", |
|
106fe61…
|
drh
|
1129 |
"dir?ci=tip", |
|
106fe61…
|
drh
|
1130 |
"dir?ci=tip&type=tree", |
|
106fe61…
|
drh
|
1131 |
"brlist", |
|
106fe61…
|
drh
|
1132 |
"info/trunk", |
|
106fe61…
|
drh
|
1133 |
}; |
|
106fe61…
|
drh
|
1134 |
|
|
106fe61…
|
drh
|
1135 |
/* Figure out which skin we are editing */ |
|
106fe61…
|
drh
|
1136 |
iSkin = atoi(PD("sk","1")); |
|
106fe61…
|
drh
|
1137 |
if( iSkin<1 || iSkin>9 ) iSkin = 1; |
|
106fe61…
|
drh
|
1138 |
|
|
106fe61…
|
drh
|
1139 |
/* Figure out if the current user is allowed to make administrative |
|
106fe61…
|
drh
|
1140 |
** changes and/or edits |
|
106fe61…
|
drh
|
1141 |
*/ |
|
106fe61…
|
drh
|
1142 |
login_check_credentials(); |
|
09e6fc3…
|
drh
|
1143 |
if( !login_is_individual() ){ |
|
09e6fc3…
|
drh
|
1144 |
login_needed(0); |
|
09e6fc3…
|
drh
|
1145 |
return; |
|
09e6fc3…
|
drh
|
1146 |
} |
|
2fac7df…
|
drh
|
1147 |
zAllowedEditors = db_get_mprintf("", "draft%d-users", iSkin); |
|
257318c…
|
drh
|
1148 |
if( g.perm.Admin ){ |
|
106fe61…
|
drh
|
1149 |
isSetup = isEditor = 1; |
|
106fe61…
|
drh
|
1150 |
}else{ |
|
106fe61…
|
drh
|
1151 |
Glob *pAllowedEditors; |
|
106fe61…
|
drh
|
1152 |
isSetup = isEditor = 0; |
|
106fe61…
|
drh
|
1153 |
if( zAllowedEditors[0] ){ |
|
106fe61…
|
drh
|
1154 |
pAllowedEditors = glob_create(zAllowedEditors); |
|
09e6fc3…
|
drh
|
1155 |
isEditor = glob_match(pAllowedEditors, g.zLogin); |
|
106fe61…
|
drh
|
1156 |
glob_free(pAllowedEditors); |
|
106fe61…
|
drh
|
1157 |
} |
|
106fe61…
|
drh
|
1158 |
} |
|
106fe61…
|
drh
|
1159 |
|
|
106fe61…
|
drh
|
1160 |
/* Initialize the skin, if requested and authorized. */ |
|
106fe61…
|
drh
|
1161 |
if( P("init3")!=0 && isEditor ){ |
|
106fe61…
|
drh
|
1162 |
skin_initialize_draft(iSkin, P("initskin")); |
|
106fe61…
|
drh
|
1163 |
} |
|
106fe61…
|
drh
|
1164 |
if( P("submit2")!=0 && isSetup ){ |
|
2fac7df…
|
drh
|
1165 |
db_set_mprintf(PD("editors",""), 0, "draft%d-users", iSkin); |
|
2fac7df…
|
drh
|
1166 |
zAllowedEditors = db_get_mprintf("", "draft%d-users", iSkin); |
|
106fe61…
|
drh
|
1167 |
} |
|
106fe61…
|
drh
|
1168 |
|
|
106fe61…
|
drh
|
1169 |
/* Publish the draft skin */ |
|
106fe61…
|
drh
|
1170 |
if( P("pub7")!=0 && PB("pub7ck1") && PB("pub7ck2") ){ |
|
106fe61…
|
drh
|
1171 |
skin_publish(iSkin); |
|
106fe61…
|
drh
|
1172 |
} |
|
106fe61…
|
drh
|
1173 |
|
|
112c713…
|
drh
|
1174 |
style_set_current_feature("skins"); |
|
106fe61…
|
drh
|
1175 |
style_header("Customize Skin"); |
|
33cc83f…
|
drh
|
1176 |
if( g.perm.Admin ){ |
|
33cc83f…
|
drh
|
1177 |
style_submenu_element("Skin-Admin", "%R/setup_skin_admin"); |
|
33cc83f…
|
drh
|
1178 |
} |
|
106fe61…
|
drh
|
1179 |
|
|
106fe61…
|
drh
|
1180 |
@ <p>Customize the look of this Fossil repository by making changes |
|
106fe61…
|
drh
|
1181 |
@ to the CSS, Header, Footer, and Detail Settings in one of nine "draft" |
|
106fe61…
|
drh
|
1182 |
@ configurations. Then, after verifying that all is working correctly, |
|
0fabc4f…
|
stephan
|
1183 |
@ publish the draft to become the new main Skin. Users can select a skin |
|
0fabc4f…
|
stephan
|
1184 |
@ of their choice from the built-in ones or the locally-edited one via |
|
c7aaaaa…
|
stephan
|
1185 |
@ <a href='%R/skins'>the /skins page</a>.</p> |
|
106fe61…
|
drh
|
1186 |
@ |
|
106fe61…
|
drh
|
1187 |
@ <a name='step1'></a> |
|
106fe61…
|
drh
|
1188 |
@ <h1>Step 1: Identify Which Draft To Use</h1> |
|
106fe61…
|
drh
|
1189 |
@ |
|
106fe61…
|
drh
|
1190 |
@ <p>The main skin of Fossil cannot be edited directly. Instead, |
|
106fe61…
|
drh
|
1191 |
@ edits are made to one of nine draft skins. A draft skin can then |
|
106fe61…
|
drh
|
1192 |
@ be published to become the default skin. |
|
106fe61…
|
drh
|
1193 |
@ Nine separate drafts are available to facilitate A/B testing.</p> |
|
106fe61…
|
drh
|
1194 |
@ |
|
106fe61…
|
drh
|
1195 |
@ <form method='POST' action='%R/setup_skin#step2' id='f01'> |
|
106fe61…
|
drh
|
1196 |
@ <p class='skinInput'>Draft skin to edit: |
|
ca19f8b…
|
drh
|
1197 |
@ <select size='1' name='sk' id='skStep1'> |
|
106fe61…
|
drh
|
1198 |
for(i=1; i<=9; i++){ |
|
106fe61…
|
drh
|
1199 |
if( i==iSkin ){ |
|
106fe61…
|
drh
|
1200 |
@ <option value='%d(i)' selected>draft%d(i)</option> |
|
106fe61…
|
drh
|
1201 |
}else{ |
|
106fe61…
|
drh
|
1202 |
@ <option value='%d(i)'>draft%d(i)</option> |
|
106fe61…
|
drh
|
1203 |
} |
|
106fe61…
|
drh
|
1204 |
} |
|
106fe61…
|
drh
|
1205 |
@ </select> |
|
106fe61…
|
drh
|
1206 |
@ </p> |
|
920ace1…
|
drh
|
1207 |
@ </form> |
|
106fe61…
|
drh
|
1208 |
@ |
|
106fe61…
|
drh
|
1209 |
@ <a name='step2'></a> |
|
106fe61…
|
drh
|
1210 |
@ <h1>Step 2: Authenticate</h1> |
|
106fe61…
|
drh
|
1211 |
@ |
|
106fe61…
|
drh
|
1212 |
if( isSetup ){ |
|
106fe61…
|
drh
|
1213 |
@ <p>As an administrator, you can make any edits you like to this or |
|
862d630…
|
drh
|
1214 |
@ any other skin. You can also authorize other users to edit this |
|
862d630…
|
drh
|
1215 |
@ skin. Any user whose login name matches the comma-separated list |
|
106fe61…
|
drh
|
1216 |
@ of GLOB expressions below is given special permission to edit |
|
106fe61…
|
drh
|
1217 |
@ the draft%d(iSkin) skin: |
|
106fe61…
|
drh
|
1218 |
@ |
|
106fe61…
|
drh
|
1219 |
@ <form method='POST' action='%R/setup_skin#step2' id='f02'> |
|
106fe61…
|
drh
|
1220 |
@ <p class='skinInput'> |
|
106fe61…
|
drh
|
1221 |
@ <input type='hidden' name='sk' value='%d(iSkin)'> |
|
106fe61…
|
drh
|
1222 |
@ Authorized editors for skin draft%d(iSkin): |
|
106fe61…
|
drh
|
1223 |
@ <input type='text' name='editors' value='%h(zAllowedEditors)'\ |
|
106fe61…
|
drh
|
1224 |
@ width='40'> |
|
106fe61…
|
drh
|
1225 |
@ <input type='submit' name='submit2' value='Change'> |
|
106fe61…
|
drh
|
1226 |
@ </p> |
|
106fe61…
|
drh
|
1227 |
@ </form> |
|
106fe61…
|
drh
|
1228 |
}else if( isEditor ){ |
|
106fe61…
|
drh
|
1229 |
@ <p>You are authorized to make changes to the draft%d(iSkin) skin. |
|
106fe61…
|
drh
|
1230 |
@ Continue to the <a href='#step3'>next step</a>.</p> |
|
106fe61…
|
drh
|
1231 |
}else{ |
|
106fe61…
|
drh
|
1232 |
@ <p>You are not authorized to make changes to the draft%d(iSkin) |
|
106fe61…
|
drh
|
1233 |
@ skin. Contact the administrator of this Fossil repository for |
|
106fe61…
|
drh
|
1234 |
@ further information.</p> |
|
106fe61…
|
drh
|
1235 |
} |
|
106fe61…
|
drh
|
1236 |
@ |
|
106fe61…
|
drh
|
1237 |
@ <a name='step3'></a> |
|
106fe61…
|
drh
|
1238 |
@ <h1>Step 3: Initialize The Draft</h1> |
|
106fe61…
|
drh
|
1239 |
@ |
|
106fe61…
|
drh
|
1240 |
if( !isEditor ){ |
|
2fac7df…
|
drh
|
1241 |
@ <p>You are not allowed to initialize draft%d(iSkin). Contact |
|
106fe61…
|
drh
|
1242 |
@ the administrator for this repository for more information. |
|
106fe61…
|
drh
|
1243 |
}else{ |
|
f3702b8…
|
drh
|
1244 |
char *zDraft = mprintf("draft%d", iSkin); |
|
106fe61…
|
drh
|
1245 |
@ <p>Initialize the draft%d(iSkin) skin to one of the built-in skins |
|
106fe61…
|
drh
|
1246 |
@ or a preexisting skin, to use as a baseline.</p> |
|
106fe61…
|
drh
|
1247 |
@ |
|
106fe61…
|
drh
|
1248 |
@ <form method='POST' action='%R/setup_skin#step4' id='f03'> |
|
106fe61…
|
drh
|
1249 |
@ <p class='skinInput'> |
|
106fe61…
|
drh
|
1250 |
@ <input type='hidden' name='sk' value='%d(iSkin)'> |
|
106fe61…
|
drh
|
1251 |
@ Initialize skin <b>draft%d(iSkin)</b> using |
|
f3702b8…
|
drh
|
1252 |
skin_emit_skin_selector("initskin", 0, zDraft); |
|
f3702b8…
|
drh
|
1253 |
fossil_free(zDraft); |
|
106fe61…
|
drh
|
1254 |
@ <input type='submit' name='init3' value='Go'> |
|
106fe61…
|
drh
|
1255 |
@ </p> |
|
106fe61…
|
drh
|
1256 |
@ </form> |
|
106fe61…
|
drh
|
1257 |
} |
|
106fe61…
|
drh
|
1258 |
@ |
|
106fe61…
|
drh
|
1259 |
@ <a name='step4'></a> |
|
106fe61…
|
drh
|
1260 |
@ <h1>Step 4: Make Edits</h1> |
|
106fe61…
|
drh
|
1261 |
@ |
|
106fe61…
|
drh
|
1262 |
if( !isEditor ){ |
|
106fe61…
|
drh
|
1263 |
@ <p>You are not authorized to make edits to the draft%d(iSkin) skin. |
|
106fe61…
|
drh
|
1264 |
@ Contact the administrator of this Fossil repository for help.</p> |
|
106fe61…
|
drh
|
1265 |
}else{ |
|
106fe61…
|
drh
|
1266 |
@ <p>Edit the components of the draft%d(iSkin) skin: |
|
106fe61…
|
drh
|
1267 |
@ <ul> |
|
106fe61…
|
drh
|
1268 |
@ <li><a href='%R/setup_skinedit?w=0&sk=%d(iSkin)' target='_blank'>CSS</a> |
|
106fe61…
|
drh
|
1269 |
@ <li><a href='%R/setup_skinedit?w=2&sk=%d(iSkin)' target='_blank'>\ |
|
106fe61…
|
drh
|
1270 |
@ Header</a> |
|
106fe61…
|
drh
|
1271 |
@ <li><a href='%R/setup_skinedit?w=1&sk=%d(iSkin)' target='_blank'>\ |
|
106fe61…
|
drh
|
1272 |
@ Footer</a> |
|
106fe61…
|
drh
|
1273 |
@ <li><a href='%R/setup_skinedit?w=3&sk=%d(iSkin)' target='_blank'>\ |
|
106fe61…
|
drh
|
1274 |
@ Details</a> |
|
9c88799…
|
drh
|
1275 |
@ <li><a href='%R/setup_skinedit?w=4&sk=%d(iSkin)' target='_blank'>\ |
|
9c88799…
|
drh
|
1276 |
@ Javascript</a> (optional) |
|
106fe61…
|
drh
|
1277 |
@ </ul> |
|
106fe61…
|
drh
|
1278 |
} |
|
106fe61…
|
drh
|
1279 |
@ |
|
106fe61…
|
drh
|
1280 |
@ <a name='step5'></a> |
|
106fe61…
|
drh
|
1281 |
@ <h1>Step 5: Verify The Draft Skin</h1> |
|
106fe61…
|
drh
|
1282 |
@ |
|
106fe61…
|
drh
|
1283 |
@ <p>To test this draft skin, insert text "/draft%d(iSkin)/" just before the |
|
106fe61…
|
drh
|
1284 |
@ operation name in the URL. Here are a few links to try: |
|
106fe61…
|
drh
|
1285 |
@ <ul> |
|
106fe61…
|
drh
|
1286 |
if( iDraftSkin && sqlite3_strglob("*/draft[1-9]", g.zBaseURL)==0 ){ |
|
106fe61…
|
drh
|
1287 |
zBase = mprintf("%.*s/draft%d", (int)strlen(g.zBaseURL)-7,g.zBaseURL,iSkin); |
|
106fe61…
|
drh
|
1288 |
}else{ |
|
106fe61…
|
drh
|
1289 |
zBase = mprintf("%s/draft%d", g.zBaseURL, iSkin); |
|
106fe61…
|
drh
|
1290 |
} |
|
106fe61…
|
drh
|
1291 |
for(i=0; i<count(azTestPages); i++){ |
|
106fe61…
|
drh
|
1292 |
@ <li><a href='%s(zBase)/%s(azTestPages[i])' target='_blank'>\ |
|
106fe61…
|
drh
|
1293 |
@ %s(zBase)/%s(azTestPages[i])</a> |
|
106fe61…
|
drh
|
1294 |
} |
|
106fe61…
|
drh
|
1295 |
fossil_free(zBase); |
|
106fe61…
|
drh
|
1296 |
@ </ul> |
|
106fe61…
|
drh
|
1297 |
@ |
|
106fe61…
|
drh
|
1298 |
@ <p>You will probably need to press Reload on your browser before any |
|
106fe61…
|
drh
|
1299 |
@ CSS changes will take effect.</p> |
|
106fe61…
|
drh
|
1300 |
@ |
|
106fe61…
|
drh
|
1301 |
@ <a hame='step6'></a> |
|
805a58c…
|
andygoth
|
1302 |
@ <h1>Step 6: Iterate</h1> |
|
106fe61…
|
drh
|
1303 |
@ |
|
106fe61…
|
drh
|
1304 |
@ <p>Repeat <a href='#step4'>step 4</a> and |
|
106fe61…
|
drh
|
1305 |
@ <a href='#step5'>step 5</a> as many times as necessary to create |
|
106fe61…
|
drh
|
1306 |
@ a production-ready skin. |
|
106fe61…
|
drh
|
1307 |
@ |
|
106fe61…
|
drh
|
1308 |
@ <a name='step7'></a> |
|
106fe61…
|
drh
|
1309 |
@ <h1>Step 7: Publish</h1> |
|
106fe61…
|
drh
|
1310 |
@ |
|
7b58c6f…
|
wyoung
|
1311 |
if( !g.perm.Admin ){ |
|
106fe61…
|
drh
|
1312 |
@ <p>Only administrators are allowed to publish draft skins. Contact |
|
106fe61…
|
drh
|
1313 |
@ an administrator to get this "draft%d(iSkin)" skin published.</p> |
|
106fe61…
|
drh
|
1314 |
}else{ |
|
106fe61…
|
drh
|
1315 |
@ <p>When the draft%d(iSkin) skin is ready for production use, |
|
7dd07b2…
|
drh
|
1316 |
@ make it the default skin by clicking the acknowledgements and |
|
106fe61…
|
drh
|
1317 |
@ pressing the button below:</p> |
|
106fe61…
|
drh
|
1318 |
@ |
|
106fe61…
|
drh
|
1319 |
@ <form method='POST' action='%R/setup_skin#step7'> |
|
106fe61…
|
drh
|
1320 |
@ <p class='skinInput'> |
|
106fe61…
|
drh
|
1321 |
@ <input type='hidden' name='sk' value='%d(iSkin)'> |
|
106fe61…
|
drh
|
1322 |
@ <input type='checkbox' name='pub7ck1' value='yes'>\ |
|
ec05984…
|
wyoung
|
1323 |
@ Skin draft%d(iSkin) has been tested and found ready for production.<br> |
|
106fe61…
|
drh
|
1324 |
@ <input type='checkbox' name='pub7ck2' value='yes'>\ |
|
106fe61…
|
drh
|
1325 |
@ The current skin should be overwritten with draft%d(iSkin).<br> |
|
106fe61…
|
drh
|
1326 |
@ <input type='submit' name='pub7' value='Publish Draft%d(iSkin)'> |
|
106fe61…
|
drh
|
1327 |
@ </p></form> |
|
106fe61…
|
drh
|
1328 |
@ |
|
106fe61…
|
drh
|
1329 |
@ <p>You will probably need to press Reload on your browser after |
|
106fe61…
|
drh
|
1330 |
@ publishing the new skin.</p> |
|
106fe61…
|
drh
|
1331 |
} |
|
106fe61…
|
drh
|
1332 |
@ |
|
106fe61…
|
drh
|
1333 |
@ <a name='step8'></a> |
|
106fe61…
|
drh
|
1334 |
@ <h1>Step 8: Cleanup and Undo Actions</h1> |
|
106fe61…
|
drh
|
1335 |
@ |
|
7b58c6f…
|
wyoung
|
1336 |
if( !g.perm.Admin ){ |
|
3a903bf…
|
drh
|
1337 |
@ <p>Administrators can optionally save or restore legacy skins, and/or |
|
3a903bf…
|
drh
|
1338 |
@ undo a prior publish. |
|
106fe61…
|
drh
|
1339 |
}else{ |
|
106fe61…
|
drh
|
1340 |
@ <p>Visit the <a href='%R/setup_skin_admin'>Skin Admin</a> page |
|
106fe61…
|
drh
|
1341 |
@ for cleanup and recovery actions. |
|
106fe61…
|
drh
|
1342 |
} |
|
036a9d5…
|
drh
|
1343 |
builtin_request_js("skin.js"); |
|
112c713…
|
drh
|
1344 |
style_finish_page(); |
|
d8ad5a2…
|
drh
|
1345 |
} |
|
d8ad5a2…
|
drh
|
1346 |
|
|
d8ad5a2…
|
drh
|
1347 |
/* |
|
d8ad5a2…
|
drh
|
1348 |
** WEBPAGE: skins |
|
d8ad5a2…
|
drh
|
1349 |
** |
|
7db623e…
|
danield
|
1350 |
** Show a list of all of the built-in skins, plus the repository skin, |
|
d8ad5a2…
|
drh
|
1351 |
** and provide the user with an opportunity to change to any of them. |
|
d8ad5a2…
|
drh
|
1352 |
*/ |
|
d8ad5a2…
|
drh
|
1353 |
void skins_page(void){ |
|
d8ad5a2…
|
drh
|
1354 |
int i; |
|
d8ad5a2…
|
drh
|
1355 |
char *zBase = fossil_strdup(g.zTop); |
|
d8ad5a2…
|
drh
|
1356 |
size_t nBase = strlen(zBase); |
|
99575d4…
|
drh
|
1357 |
login_check_credentials(); |
|
d8ad5a2…
|
drh
|
1358 |
if( iDraftSkin && sqlite3_strglob("*/draft?", zBase)==0 ){ |
|
d8ad5a2…
|
drh
|
1359 |
nBase -= 7; |
|
d8ad5a2…
|
drh
|
1360 |
zBase[nBase] = 0; |
|
d8ad5a2…
|
drh
|
1361 |
}else if( pAltSkin ){ |
|
d8ad5a2…
|
drh
|
1362 |
char *zPattern = mprintf("*/skn_%s", pAltSkin->zLabel); |
|
d8ad5a2…
|
drh
|
1363 |
if( sqlite3_strglob(zPattern, zBase)==0 ){ |
|
d8ad5a2…
|
drh
|
1364 |
nBase -= strlen(zPattern)-1; |
|
d8ad5a2…
|
drh
|
1365 |
zBase[nBase] = 0; |
|
d8ad5a2…
|
drh
|
1366 |
} |
|
d8ad5a2…
|
drh
|
1367 |
fossil_free(zPattern); |
|
275da70…
|
danield
|
1368 |
} |
|
d8ad5a2…
|
drh
|
1369 |
style_header("Skins"); |
|
816f6c0…
|
stephan
|
1370 |
if( iDraftSkin || nSkinRank<=1 ){ |
|
816f6c0…
|
stephan
|
1371 |
@ <p class="warning">Warning: |
|
816f6c0…
|
stephan
|
1372 |
if( iDraftSkin>0 ){ |
|
816f6c0…
|
stephan
|
1373 |
@ you are using a draft skin, |
|
816f6c0…
|
stephan
|
1374 |
}else{ |
|
816f6c0…
|
stephan
|
1375 |
@ this fossil instance was started with a hard-coded skin |
|
24e015d…
|
drh
|
1376 |
@ value |
|
816f6c0…
|
stephan
|
1377 |
} |
|
7db623e…
|
danield
|
1378 |
@ which supersedes any option selected below. A skin selected |
|
24e015d…
|
drh
|
1379 |
@ below will be recorded in your |
|
24e015d…
|
drh
|
1380 |
@ "%z(href("%R/fdscookie"))fossil_display_settings</a>" cookie |
|
816f6c0…
|
stephan
|
1381 |
@ but will not be used so long as the site has a |
|
816f6c0…
|
stephan
|
1382 |
@ higher-priority skin in place. |
|
3339420…
|
drh
|
1383 |
@ </p> |
|
3339420…
|
drh
|
1384 |
} |
|
685c7d0…
|
drh
|
1385 |
@ <p>The following skins are available for this repository:</p> |
|
685c7d0…
|
drh
|
1386 |
@ <ul> |
|
2ac49d3…
|
drh
|
1387 |
for(i=0; i<count(aBuiltinSkin); i++){ |
|
2ac49d3…
|
drh
|
1388 |
if( pAltSkin==&aBuiltinSkin[i] ){ |
|
2ac49d3…
|
drh
|
1389 |
@ <li> %h(aBuiltinSkin[i].zDesc) ← <i>Currently in use</i> |
|
2ac49d3…
|
drh
|
1390 |
}else{ |
|
2ac49d3…
|
drh
|
1391 |
char *zUrl = href("%R/skins?skin=%T", aBuiltinSkin[i].zLabel); |
|
2ac49d3…
|
drh
|
1392 |
@ <li> %z(zUrl)%h(aBuiltinSkin[i].zDesc)</a> |
|
2ac49d3…
|
drh
|
1393 |
} |
|
2ac49d3…
|
drh
|
1394 |
} |
|
b828d8f…
|
drh
|
1395 |
if( skin_exists_custom() ){ |
|
b828d8f…
|
drh
|
1396 |
if( pAltSkin==0 && zAltSkinDir==0 && iDraftSkin==0 ){ |
|
b828d8f…
|
drh
|
1397 |
@ <li> Custom skin for this repository ← <i>Currently in use</i> |
|
b828d8f…
|
drh
|
1398 |
}else{ |
|
b828d8f…
|
drh
|
1399 |
@ <li> %z(href("%R/skins?skin=custom"))\ |
|
b828d8f…
|
drh
|
1400 |
@ Custom skin for this repository</a> |
|
24e015d…
|
drh
|
1401 |
} |
|
24e015d…
|
drh
|
1402 |
} |
|
d8ad5a2…
|
drh
|
1403 |
@ </ul> |
|
24e015d…
|
drh
|
1404 |
if( iSkinSource<SKIN_FROM_CUSTOM ){ |
|
24e015d…
|
drh
|
1405 |
@ <p>The current skin is selected by |
|
24e015d…
|
drh
|
1406 |
switch( iSkinSource ){ |
|
24e015d…
|
drh
|
1407 |
case SKIN_FROM_DRAFT: |
|
24e015d…
|
drh
|
1408 |
@ the "debugN" prefix on the PATH_INFO portion of the URL. |
|
24e015d…
|
drh
|
1409 |
break; |
|
24e015d…
|
drh
|
1410 |
case SKIN_FROM_CMDLINE: |
|
24e015d…
|
drh
|
1411 |
@ the "--skin" command-line option on the Fossil server. |
|
24e015d…
|
drh
|
1412 |
break; |
|
24e015d…
|
drh
|
1413 |
case SKIN_FROM_CGI: |
|
24e015d…
|
drh
|
1414 |
@ the "skin:" property in the CGI script that runs the Fossil server. |
|
24e015d…
|
drh
|
1415 |
break; |
|
24e015d…
|
drh
|
1416 |
case SKIN_FROM_QPARAM: |
|
24e015d…
|
drh
|
1417 |
@ the "skin=NAME" query parameter on the URL. |
|
24e015d…
|
drh
|
1418 |
break; |
|
24e015d…
|
drh
|
1419 |
case SKIN_FROM_COOKIE: |
|
24e015d…
|
drh
|
1420 |
@ the "skin" property in the |
|
24e015d…
|
drh
|
1421 |
@ "%z(href("%R/fdscookie"))fossil_display_settings</a>" cookie. |
|
24e015d…
|
drh
|
1422 |
break; |
|
18d76ff…
|
drh
|
1423 |
case SKIN_FROM_SETTING: |
|
18d76ff…
|
drh
|
1424 |
@ the "default-skin" setting on the repository. |
|
18d76ff…
|
drh
|
1425 |
break; |
|
24e015d…
|
drh
|
1426 |
} |
|
24e015d…
|
drh
|
1427 |
} |
|
99575d4…
|
drh
|
1428 |
if( iSkinSource==SKIN_FROM_COOKIE || iSkinSource==SKIN_FROM_QPARAM ){ |
|
99575d4…
|
drh
|
1429 |
@ <ul> |
|
99575d4…
|
drh
|
1430 |
@ <li> %z(href("%R/skins?skin="))<i>Let Fossil choose \ |
|
99575d4…
|
drh
|
1431 |
@ which skin to use</i></a> |
|
99575d4…
|
drh
|
1432 |
@ </ul> |
|
99575d4…
|
drh
|
1433 |
} |
|
d8ad5a2…
|
drh
|
1434 |
style_finish_page(); |
|
99575d4…
|
drh
|
1435 |
if( P("skin")!=0 ){ |
|
99575d4…
|
drh
|
1436 |
sqlite3_uint64 x; |
|
99575d4…
|
drh
|
1437 |
sqlite3_randomness(sizeof(x), &x); |
|
99575d4…
|
drh
|
1438 |
cgi_redirectf("%R/skins/%llx", x); |
|
99575d4…
|
drh
|
1439 |
} |
|
d8ad5a2…
|
drh
|
1440 |
fossil_free(zBase); |
|
007d0a9…
|
drh
|
1441 |
} |