/
cp_skin_multi.php
409 lines (341 loc) · 16.2 KB
/
cp_skin_multi.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
<?php
/*
** Control Panel :: The Great Multi-Skin Editor (Behold!)
** for CodewiseBlog Multi-User
**
** by William R. Fraser <wrf@codewise.org>
** Copyright (c) 2005-2008 Codewise.org
*/
/*
** This file is part of CodewiseBlog
**
** CodewiseBlog is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** CodewiseBlog is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with CodewiseBlog; if not, write to the Free Software
** Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
$current = "skin";
if(isset($_POST['skinid']))
{
// check to make sure the skin exists
$q = $db->issue_query("SELECT skinid FROM skins WHERE skinid = ".$db->prepare_value($_POST['skinid']));
if($db->num_rows[$q] != 1)
{
$body = skinvoodoo("error", "error", array("message" => "No such Skin ID."));
return;
}
// export skin as VoodooArchive XML file
if(isset($_POST['export']))
{
require("skin_exporter_xml.php");
// generate XML. Only export full skin if user is root.
$xml = skin_exporter_xml($_POST['skinid'], BLOGID == 1);
// grab name
$q = $db->issue_query("SELECT name FROM skins WHERE skinid = ".$db->prepare_value($_POST['skinid']));
$name = $db->fetch_var($q);
/* force 'Save As' dialog. Propose filename as [skin name].cwb.xml with
** non-windows-suitable characters and spaces replaced with
** underscores. */
header("Content-Type: text/xml");
header("Content-Disposition: attachment; filename=".str_replace(array(" ","/","?","<",">","\\",":","*","|","\"","^"), "_", $name).".cwb.xml");
echo $xml;
exit;
}
if(isset($_POST['delete'])) {
if($_POST['skinid'] == "00000000000000000000000000000000")
{
$body = skinvoodoo("error", "error", array("message" => "You cannot delete the master skin."));
return;
}
$db->issue_query("SELECT blogid FROM skins WHERE skinid = ".$db->prepare_value($_POST['skinid']));
if($db->fetch_var == 1 && BLOGID != 1)
{
$body = skinvoodoo("error", "error", array("message" => "You cannot delete a built-in skin."));
return;
}
/* for users, don't actually delete, just disown (to blogid 0).
** Only root can actually delete. */
if(BLOGID != 1)
{
$name = $db->fetch_var($db->issue_query("SELECT name FROM skins WHERE skinid = ".$db->prepare_value($_POST['skinid'])));
$db->update("skins", array("blogid" => 0, "name" => $name . " (deleted by ".BLOGID.")"), array("skinid" => $_POST['skinid']));
$body = "<p>Your skin has been deleted. If this is in error, copy down the Skin ID below and contact an administrator."
. "They can recover your skin.<br /><br />Skin ID: <b>{$_POST['skinid']}</b>";
} else {
$db->issue_query("DELETE FROM skins WHERE skinid = ".$db->prepare_value($_POST['skinid']));
$body = skinvoodoo("error", "notify", array("message" => "Skin {$_POST['skinid']} deleted."));
}
// if it's the current skin being deleted, switch to master
if(SKINID == $_POST['skinid'])
$db->update("blogs", array("skinid" => DEFAULT_SKINID), array("blogid" => BLOGID));
} else {
$owner = $db->fetch_var($db->issue_query("SELECT blogid FROM skins WHERE skinid = ".$db->prepare_value($_POST['skinid'])));
/*
IF:
not owner
and not root
and not just USEing a builtin skin
or copying
copy skin
*/
if($owner != BLOGID
&& BLOGID != 1
&& !(isset($_POST['use']) && $owner == 1 )
|| isset($_POST['copy']))
{
// pull skin from DB
$q = $db->issue_query("SELECT * FROM skins WHERE skinid = ".$db->prepare_value($_POST['skinid']));
$skin = $db->fetch_row($q, 0, L1SQL_ASSOC);
// change ownership
$skin['blogid'] = BLOGID;
do {
// generate a new skinid
$skin['skinid'] = md5(uniqid(mt_rand(), TRUE));
// make sure the skinid isn't a dupe (unlikely, but possible)
} while($db->num_rows[ $db->issue_query("SELECT skinid FROM skins WHERE skinid = '".$skin['skinid']."'") ] > 0);
// copying the master skin is a special case
if($_POST['skinid'] == "00000000000000000000000000000000")
{
$new_skin = array();
foreach($skin as $section => $contents)
{
switch($section)
{
/* Since the master is owned by root, the check below
** to eliminate duplicates doesn't work. This gets
** around that. */
case "name": $contents .= " [copy]";
break;
// these fields stay the same
case "skinid":
case "blogid":
case "description": break;
/* All the sections should be NULL so that the editor
** properly indicates that you're using the master skin
** for all sections, instead of just copying the text
** over, which would make the editor think every section
** was changed. */
default: $contents = NULL;
}
$new_skin[$section] = $contents;
}
$skin = $new_skin;
} elseif($owner == 1) {
/* copying builtin skins don't need all the above modifications,
** just appending [copy] to the end is enough */
$skin['name'] .= " [copy]";
}
// make sure no two skins with the same owner have the same name
while( $db->num_rows[ $ff = $db->issue_query("SELECT * FROM skins WHERE blogid = '".BLOGID."' AND name = ".$db->prepare_value($skin['name'])) ] > 0)
{
$skin['name'] .= " [copy]";
}
// add skin to DB
$db->insert("skins", $skin);
// Edit the copy
$_POST['skinid'] = $skin['skinid'];
/* if the user did not explicitly request this, tell them about the
** copy procedure */
if(!isset($_POST['copy']))
$GLOBALS['NOTIFY'] .= "You cannot edit someone else's skin, so a copy has been made.<br />";
}
if(isset($_POST['save_skin']))
{
// description changes the title and possibly the owner too
if($_POST['section'] == "description")
{
$db->update("skins", array("name" => $_POST['skin_name']), array("skinid" => $_POST['skinid']));
// root can change the owner too
if(BLOGID == 1)
$db->update("skins", array("blogid" => $_POST['skin_owner']), array("skinid" => $_POST['skinid']));
}
$db->update("skins", array($_POST['section'] => $_POST['section_content']), array("skinid" => $_POST['skinid']));
$GLOBALS['NOTIFY'] .= "Skin saved";
} elseif(isset($_POST['revert'])) {
$db->update("skins", array($_POST['section'] => NULL), array("skinid" => $_POST['skinid']));
$GLOBALS['NOTIFY'] .= "Reverted section to master skin.<br />";
}
if(isset($_POST['use']))
{
$db->update("blogs", array("skinid" => $_POST['skinid']), array("blogid" => BLOGID));
$body = skinvoodoo("error", "notify", array("message" => "Now using the selected skin."));
return;
}
// get the section edit box to redisplay after resizing or saving or reverting
if(isset($_POST['resize']) || isset($_POST['save_skin']) || isset($_POST['revert']))
$_POST['section_sel'] = $_POST['section'];
// bring up the description and title by default
if(!isset($_POST['section_sel']))
$_POST['section_sel'] = "description";
// generate the list of sections
$q = $db->issue_query("DESCRIBE skins");
$desc = $db->fetch_all($q, L1SQL_ASSOC);
$sectionlist = "";
foreach($desc as $col)
{
/* for non-root users, don't display the controlpanel and
** registration sections. */
if(BLOGID != 1)
{
if(strpos($col['Field'], "controlpanel") === 0
|| $col['Field'] == "register")
{
continue;
}
}
switch($col['Field'])
{
case "skinid": // skinid gets displayed at the top of every section's page
case "blogid": // <- these don't get an entry in the section list, but instead
case "name": // <- get lumped together on the with the 'description' section.
continue;
case $_POST['section_sel']:
$sectionlist .= skinvoodoo("controlpanel_skin_multi", "sectionlist_current", array("section" => $col['Field']));
break;
default:
$sectionlist .= skinvoodoo("controlpanel_skin_multi", "sectionlist_entry", array("section" => $col['Field']));
break;
}
}
// get the section from DB
$q = $db->issue_query("SELECT ".$db->prepare_value($_POST['section_sel'], FALSE)." FROM skins WHERE skinid = ".$db->prepare_value($_POST['skinid']));
$skin = $db->fetch_var($q);
if($skin === NULL)
{
$using_master = TRUE;
$q = $db->issue_query("SELECT ".$db->prepare_value($_POST['section_sel'], FALSE)." FROM skins WHERE skinid = '00000000000000000000000000000000'");
$skin = $db->fetch_var($q);
} else {
$using_master = FALSE;
}
/* in the master skin, the section is always the master, not when it is
** NULL like for other skins */
if($_POST['skinid'] == "00000000000000000000000000000000")
$using_master = TRUE;
// for the description, show the title edit field as well
if($_POST['section_sel'] == "description")
{
$name = $db->fetch_var($db->issue_query("SELECT name FROM skins WHERE skinid = ".$db->prepare_value($_POST['skinid'])));
$content = skinvoodoo("controlpanel_skin_multi", "skin_name", array("name" => $name));
// root can change the owner too
if(BLOGID == 1)
$content .= skinvoodoo("controlpanel_skin_multi", "skin_owner", array("owner" => $owner));
} else {
$content = "";
}
$content .= skinvoodoo("controlpanel_skin_multi", "section_edit", array(
"section_name" => $_POST['section_sel'],
"using_master" => $using_master,
"autoresize" => HTTP.BASE_DOMAIN.INSTALLED_PATH."/cwb/autoresize.js",
"rows" => $_POST['rows'] ? $_POST['rows'] : 30,
"cols" => $_POST['cols'] ? $_POST['cols'] : 80,
"skinid" => $_POST['skinid'],
"section_content" => str_replace(
array("%{", "\${" ),
array("%{", "${" ),
htmlspecialchars($skin)),
));
/* <iframe> containing the local variable reference, scrolled to the
** appropriate section */
$documentation = "<iframe src=\"http://"
. DEFAULT_SUBDOMAIN . BASE_DOMAIN . INSTALLED_PATH
. "doc/voodoo/localvars.html#{$_POST['section_sel']}\" height=\"100%\" width=\"300\" /></iframe>";
$body = skinvoodoo("controlpanel_skin_multi", "", array(
"posturl" => INDEX_URL . "?controlpanel:skin",
"sectionlist" => $sectionlist,
"varlist" => $documentation,
"content" => $content,
"skinid" => $_POST['skinid'],
"section_name" => isset($_POST['section_sel'])
? $_POST['section_sel']
: FALSE,
));
}
// Import uploaded VoodooArchive XML file
} elseif(isset($_POST['import'])) {
require("skin_importer_xml.php");
if(!is_uploaded_file($_FILES['xmlfile']['tmp_name']))
{
$body = skinvoodoo("error", "error", array("message" => "Bogus upload file"));
return;
}
$xml = file_get_contents($_FILES['xmlfile']['tmp_name']);
unlink($_FILES['xmlfile']['tmp_name']);
if(!preg_match("/[a-f0-9]{32}/", $ret = skin_importer_xml($xml)))
{
$body = skinvoodoo("error", "error", array("message" => "Skin import failed: ".htmlspecialchars($ret)));
return;
} else {
//$body = "<b>Skin import successful.</b><br />New skin id: $ret";
$body = skinvoodoo("controlpanel_skin_multi", "import_successful", array(
"posturl" => INDEX_URL . "?controlpanel:skin",
"newskinid" => $ret,
));
return;
}
} else {
if(BLOGID != 1)
{
/* get the skinid and name of all the builtin skins (those owned by
** root) */
$q = $db->issue_query("SELECT skinid, name FROM skins WHERE blogid = '1'");
$root_skins = $db->fetch_all($q, L1SQL_ASSOC);
// get the skinid and name of all the skins owned by the user
$q = $db->issue_query("SELECT skinid, name FROM skins WHERE blogid = '".BLOGID."'");
$user_skins = $db->fetch_all($q, L1SQL_ASSOC);
// separator
$skinids .= skinvoodoo(
"controlpanel_skin_multi",
"saved_skinids_separator",
array("text" => "Built-In Skins:")
);
foreach($root_skins as $skin)
{
if(SKINID == $skin['skinid'])
$skinids .= skinvoodoo("controlpanel_skin_multi", "saved_skinids_current", array("skinid" => $skin['skinid'], "name" => $skin['name']));
else
$skinids .= skinvoodoo("controlpanel_skin_multi", "saved_skinids_entry", array("skinid" => $skin['skinid'], "name" => $skin['name']));
}
// separator
$skinids .= skinvoodoo("controlpanel_skin_multi", "saved_skinids_separator", array("text" => "Your Skins:"));
foreach($user_skins as $skin)
{
if(SKINID == $skin['skinid'])
$skinids .= skinvoodoo("controlpanel_skin_multi", "saved_skinids_current", array("skinid" => $skin['skinid'], "name" => $skin['name']));
else
$skinids .= skinvoodoo("controlpanel_skin_multi", "saved_skinids_entry", array("skinid" => $skin['skinid'], "name" => $skin['name']));
}
} else {
// get the skins from BLOGID 1 (builtin skins)
$q = $db->issue_query("SELECT skinid, name FROM skins WHERE blogid = '1'");
$builtin_skins = $db->fetch_all($q, L1SQL_ASSOC);
// get the skins from BLOGID 0 (disowned skins)
$q = $db->issue_query("SELECT skinid, name FROM skins WHERE blogid = '0'");
$disowned_skins = $db->fetch_all($q, L1SQL_ASSOC);
$skinids .= skinvoodoo("controlpanel_skin_multi", "saved_skinids_separator", array("text" => "Built-In Skins:"));
foreach($builtin_skins as $skin)
{
$skinids .= skinvoodoo("controlpanel_skin_multi", "saved_skinids_entry", array("skinid" => $skin['skinid'], "name" => $skin['name']));
}
$skinids .= skinvoodoo("controlpanel_skin_multi", "saved_skinids_separator", array("text" => "Disowned Skins:"));
foreach($disowned_skins as $skin)
{
$skinids .= skinvoodoo("controlpanel_skin_multi", "saved_skinids_entry", array("skinid" => $skin['skinid'], "name" => $skin['name']));
}
}
$body = skinvoodoo("controlpanel_skin_multi", "skin_select", array(
"posturl" => INDEX_URL . "?controlpanel:skin",
"saved_skinids" => $skinids,
"max_file_size" => str_replace("M", "000000", str_replace("K", "000", ini_get("upload_max_filesize"))),
));
}
?>