/
edit.php
executable file
·3446 lines (2924 loc) · 129 KB
/
edit.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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
// Barebones CMS
// (C) 2015 CubicleSoft. All Rights Reserved.
if (!defined("BB_FILE")) exit();
// The editor should be used when the credentials and/or tools systems need to be used.
define("BB_MODE_EDIT", 1);
define("BB_CORE_VER", "1.3");
// Drag in debugging capabilities.
require_once ROOT_PATH . "/" . SUPPORT_PATH . "/debug.php";
SetDebugLevel();
// Load core functions.
require_once ROOT_PATH . "/" . SUPPORT_PATH . "/bb_functions.php";
if (USE_HTTPS && !BB_IsSSLRequest())
{
header("Location: " . BB_GetFullRequestURLBase("https") . "?bb_action=bb_main_edit");
exit();
}
// Load backend multilingual support.
if (!defined("LANG_PATH")) define("LANG_PATH", "lang");
if (!defined("DEFAULT_LANG")) define("DEFAULT_LANG", "");
BB_InitLangmap(ROOT_PATH . "/" . LANG_PATH . "/", DEFAULT_LANG);
// Load plugins.
$plugins = BB_GetPluginList();
foreach ($plugins as $file) require_once ROOT_PATH . "/" . PLUGIN_PATH . "/" . $file . "/index.php";
BB_RunPluginAction("plugins_loaded");
// Make sure an account is loaded. Using REQUEST allows automation and Flash-based uploads to work.
$bb_account = false;
if (isset($_REQUEST["bbl"]))
{
require_once "accounts.php";
BB_RunPluginAction("accounts_loaded");
if (isset($bb_accounts["sessions"][$_REQUEST["bbl"]]))
{
$bb_session = $bb_accounts["sessions"][$_REQUEST["bbl"]];
if ($bb_session["expire"] < time()) BB_DeleteExpiredUserSessions();
else $bb_account = $bb_accounts["users"][$bb_session["username"]];
}
}
if ($bb_account === false)
{
BB_RunPluginAction("access_denied");
echo htmlspecialchars(BB_Translate("Invalid credentials."));
exit();
}
if (isset($bb_account["lang"]) && $bb_account["lang"] != "") BB_SetLanguage(ROOT_PATH . "/" . LANG_PATH . "/", $bb_account["lang"]);
BB_RunPluginAction("account_valid");
// Load in a revision, if required.
$bb_revision_num = -1;
$bb_revision = false;
$bb_revision_writeable = true;
BB_RunPluginAction("pre_revision_load");
if (isset($_REQUEST["bb_revnum"]) && (int)$_REQUEST["bb_revnum"] > -1)
{
require_once $bb_dir . "/" . $bb_file . "_" . $bb_pref_lang . "_rev.php";
$bb_revision_num = (int)$_REQUEST["bb_revnum"];
if (!isset($bb_langpagerevisions["revisions"][$bb_revision_num])) $bb_revision_num = -1;
else
{
$bb_revision = $bb_langpagerevisions["revisions"][$bb_revision_num];
$bb_langpage = unserialize($bb_revision[1]);
$bb_revision_writeable = BB_IsRevisionWriteable($bb_revision_num);
BB_RunPluginAction("revision_loaded");
}
}
BB_RunPluginAction("post_revision_load");
// Create a valid language-level security token (also known as a 'nonce').
function BB_CreateSecurityToken($bbaction, $wid = "", $extra = "")
{
global $bb_langpage, $bb_pref_lang, $bb_revision_num, $bb_session;
$str = $bbaction . ":" . $bb_pref_lang . ":" . $wid . ":" . $bb_revision_num . ":";
if (is_string($extra) && $extra != "")
{
$extra = explode(",", $extra);
foreach ($extra as $key)
{
$key = trim($key);
if ($key != "" && isset($_REQUEST[$key])) $str .= (string)$_REQUEST[$key] . ":";
}
}
else if (is_array($extra))
{
foreach ($extra as $val) $str .= $val . ":";
}
return hash_hmac("sha1", $str, pack("H*", $bb_langpage["pagerand"]) . ":" . pack("H*", $bb_session["session2"]) . ":" . pack("H*", BASE_RAND_SEED2));
}
// Supporting functions to simplify generating and validating security token based links.
function BB_IsSecExtraOpt($opt)
{
return (isset($_REQUEST["bb_sec_extra"]) && strpos("," . $_REQUEST["bb_sec_extra"] . ",", "," . $opt . ",") !== false);
}
function BB_CreatePropertiesLink($title, $bbaction, $extra = array(), $confirm = "", $useprops2 = false, $parentwindow = false)
{
if (!isset($extra["wid"])) $wid = "";
else
{
$wid = $extra["wid"];
unset($extra["wid"]);
}
$extra2 = "";
foreach ($extra as $key => $val) $extra2 .= ", '" . htmlspecialchars(BB_JSSafe($key)) . "' : '" . htmlspecialchars(BB_JSSafe($val)) . "'";
return "<a href=\"#\" onclick=\"" . ($confirm != "" ? "if (confirm('" . htmlspecialchars(BB_JSSafe($confirm)) . "')) " : "return ") . ($parentwindow ? "window.parent." : "") . "LoadProperties" . ($useprops2 ? "2" : "") . "({'bb_action' : '" . htmlspecialchars(BB_JSSafe($bbaction)) . "'" . ($wid != "" ? ", 'wid' : '" . htmlspecialchars(BB_JSSafe($wid)) . "'" : "") . $extra2 . ", 'bbt' : '" . htmlspecialchars(BB_JSSafe(BB_CreateSecurityToken($bbaction, $wid, array_values($extra)))) . "', 'bb_sec_extra' : '" . htmlspecialchars(BB_JSSafe(implode(",", array_keys($extra)))) . "'});" . ($confirm != "" ? " return false;" : "") . "\">" . htmlspecialchars($title) . "</a>";
}
function BB_CreatePropertiesJS($bbaction, $extra = array(), $full = false, $usebbl = false)
{
global $bb_pref_lang, $bb_revision_num;
if (!isset($extra["wid"])) $wid = "";
else
{
$wid = $extra["wid"];
unset($extra["wid"]);
}
$options = array();
if ($full)
{
if ($usebbl) $options["bbl"] = (string)$_REQUEST["bbl"];
$options["lang"] = (string)$bb_pref_lang;
if ($bb_revision_num > -1) $options["bb_revnum"] = (string)$bb_revision_num;
}
$options["bb_action"] = $bbaction;
if ($wid != "") $options["wid"] = (string)$wid;
foreach ($extra as $key => $val) $options[(string)$key] = (string)$val;
$options["bbt"] = BB_CreateSecurityToken($bbaction, $wid, array_values($extra));
$options["bb_sec_extra"] = implode(",", array_keys($extra));
BB_RunPluginActionInfo("bb_createpropertiesjs", $options);
return json_encode($options);
}
function BB_CreateWidgetPropertiesLink($title, $bbaction, $extra = array(), $confirm = "", $useprops2 = false)
{
global $bb_widget_id;
$extra["wid"] = $bb_widget_id;
return BB_CreatePropertiesLink($title, $bbaction, $extra, $confirm, $useprops2, true);
}
function BB_CreateWidgetPropertiesJS($bbaction, $extra = array(), $full = false, $usebbl = false)
{
global $bb_widget_id;
$extra["wid"] = $bb_widget_id;
return BB_CreatePropertiesJS($bbaction, $extra, $full, $usebbl);
}
// Check the security token. If it doesn't exist, load the main page.
if ($_REQUEST["bb_action"] != "bb_main_edit" && (!isset($_REQUEST["bbt"]) || $_REQUEST["bbt"] != BB_CreateSecurityToken($_REQUEST["bb_action"], (isset($_REQUEST["wid"]) ? $_REQUEST["wid"] : ""), (isset($_REQUEST["bb_sec_extra"]) ? $_REQUEST["bb_sec_extra"] : ""))))
{
echo htmlspecialchars(BB_Translate("Invalid security token."));
exit();
}
BB_RunPluginAction("access_granted");
// Select cache profile.
if (isset($_REQUEST["bb_profile"]) && isset($bb_profiles[$_REQUEST["bb_profile"]])) $bb_profile = (string)$_REQUEST["bb_profile"];
else $bb_profile = "";
if (preg_replace('/[^A-Za-z0-9_\-]/', "", $bb_profile) !== $bb_profile)
{
echo htmlspecialchars(BB_Translate("Invalid cache profile. Cache profile can only contain alphanumeric (A-Z, 0-9), '_', and '-' characters."));
exit();
}
// Load widgets.
BB_RunPluginAction("pre_widgets_load");
foreach ($bb_langpage["widgets"] as $id => $data)
{
$bb_widget->SetID($id);
BB_RunPluginAction("pre_widget_load");
if ($bb_widget->_m === false && $bb_widget->_a !== false && file_exists(ROOT_PATH . "/" . WIDGET_PATH . "/" . $bb_widget->_file))
{
require_once ROOT_PATH . "/" . WIDGET_PATH . "/" . $bb_widget->_file;
BB_InitWidget();
}
BB_RunPluginAction("post_widget_load");
}
$bb_widget->SetID("");
BB_RunPluginAction("post_widgets_load");
// Master widget functions.
function BB_MasterWidgetManager($name)
{
global $bb_account, $bb_mode, $bb_widget, $bb_langpage, $bb_css, $bb_js;
if ($bb_mode == "head")
{
$bb_css[ROOT_URL . "/" . SUPPORT_PATH . "/css/widgets.css"] = ROOT_PATH . "/" . SUPPORT_PATH . "/css/widgets.css";
$bb_js[ROOT_URL . "/" . SUPPORT_PATH . "/js/widgets.js"] = ROOT_PATH . "/" . SUPPORT_PATH . "/js/widgets.js";
}
else if ($bb_account["type"] == "dev" || $bb_account["type"] == "design")
{
$widget = $bb_langpage["widgets"][$name];
if ($bb_mode == "body")
{
?>
<div class="bb_mw_manager">
<b><?php echo htmlspecialchars(BB_Translate("%s Options", $widget["_f"])); ?></b><br />
<div class="bb_mw_manager_links">
<?php
echo BB_CreatePropertiesLink(BB_Translate("Add Widget"), "bb_main_edit_widgets_add_widget", array("wid" => $name), "", false, true);
if (count($widget["_ids"]) > 1) echo BB_CreatePropertiesLink(BB_Translate("Reorder Widgets"), "bb_main_edit_widgets_reorder", array("wid" => $name), "", false, true);
// Find orphaned widgets.
foreach ($bb_langpage["widgets"] as $id => $widget2)
{
if ($widget2["_a"] === false)
{
echo BB_CreatePropertiesLink(BB_Translate("Delete '%s'.", $widget2["_f"]), "bb_main_edit_widgets_delete_widget", array("wid" => $id), BB_Translate("Are you sure you want to delete '%s'?", $widget2["_f"]), false, true);
if ($widget2["_m"] === false) echo BB_CreatePropertiesLink(BB_Translate("Attach '%s'.", $widget2["_f"]), "bb_main_edit_widgets_attach_widget", array("wid" => $id, "pid" => $name), "", false, true);
}
}
?>
</div>
</div>
<?php
}
}
}
function BB_MasterWidgetPreWidget($displaymwm)
{
global $bb_account, $bb_widget, $bb_widget_id, $bb_widget_instances;
ob_start();
$bb_widget_instances[$bb_widget_id]->PreWidget();
if ($displaymwm && ($bb_account["type"] == "dev" || $bb_account["type"] == "design"))
{
echo BB_CreateWidgetPropertiesLink(BB_Translate("Detach"), "bb_main_edit_widgets_detach_widget");
echo BB_CreateWidgetPropertiesLink(BB_Translate("Delete"), "bb_main_edit_widgets_delete_widget", array(), BB_Translate("Are you sure you want to detach and delete this widget?"));
}
$data = ob_get_contents();
ob_end_clean();
$data = trim($data);
if ($data != "")
{
?>
<div class="bb_mw_manager">
<div class="bb_mw_manager_type">[<?php echo htmlspecialchars($bb_widget->_n); ?>]</div>
<b><?php echo htmlspecialchars(BB_Translate("%s Options", $bb_widget->_f)); ?></b><br />
<div class="bb_mw_manager_links">
<?php echo $data; ?>
</div>
</div>
<?php
}
}
function BB_PropertyForm($options)
{
global $bb_pref_lang, $bb_revision_num;
BB_RunPluginActionInfo("pre_bb_propertyform", $options);
$autofocus = false;
?>
<div class="propclose"><a href="#" onclick="return CloseProperties();">X</a></div>
<div class="proptitle"><?php echo htmlspecialchars(BB_Translate($options["title"])); ?></div>
<div class="propdesc"><?php echo htmlspecialchars(BB_Translate($options["desc"])); ?><?php if (isset($options["htmldesc"])) echo $options["htmldesc"]; ?></div>
<div class="propinfo"></div>
<div class="propmain">
<?php
if (isset($options["submit"]) || (isset($options["useform"]) && $options["useform"]))
{
?>
<form id="propform" method="post" onsubmit="return SendProperties();">
<input type="hidden" name="bb_action" value="<?php echo htmlspecialchars(isset($options["bb_action"]) && is_string($options["bb_action"]) ? $options["bb_action"] : $_REQUEST["bb_action"] . "_submit"); ?>" />
<input type="hidden" name="lang" value="<?php echo htmlspecialchars($bb_pref_lang); ?>" />
<?php
if ($bb_revision_num > -1)
{
?>
<input type="hidden" name="bb_revnum" value="<?php echo $bb_revision_num; ?>" />
<?php
}
if (isset($_REQUEST["wid"]))
{
?>
<input type="hidden" name="wid" value="<?php echo htmlspecialchars($_REQUEST["wid"]); ?>" />
<?php
}
$extra = array();
if (isset($options["hidden"]))
{
foreach ($options["hidden"] as $name => $value)
{
?>
<input type="hidden" name="<?php echo htmlspecialchars($name); ?>" value="<?php echo htmlspecialchars($value); ?>" />
<?php
$extra[] = $value;
}
?>
<input type="hidden" name="bb_sec_extra" value="<?php echo htmlspecialchars(implode(",", array_keys($options["hidden"]))); ?>" />
<?php
}
?>
<input type="hidden" name="bbt" value="<?php echo htmlspecialchars(BB_CreateSecurityToken((isset($options["bb_action"]) && is_string($options["bb_action"]) ? $options["bb_action"] : $_REQUEST["bb_action"] . "_submit"), (isset($_REQUEST["wid"]) ? $_REQUEST["wid"] : ""), $extra)); ?>" />
<?php
unset($extra);
}
if (isset($options["fields"]))
{
?>
<div class="formfields<?php if (count($options["fields"]) == 1 && !isset($options["fields"][0]["title"])) echo " alt"; ?>">
<?php
foreach ($options["fields"] as $num => $field)
{
?>
<div class="formitem">
<?php
if (isset($field["title"]))
{
?>
<div class="formitemtitle"><?php echo htmlspecialchars(BB_Translate($field["title"])); ?></div>
<?php
}
switch ($field["type"])
{
case "static":
{
?>
<div class="static"><?php echo htmlspecialchars($field["value"]); ?></div>
<?php
break;
}
case "text":
{
if ($autofocus === false) $autofocus = htmlspecialchars("f" . $num . "_" . $field["name"]);
?>
<input class="text" type="text" id="<?php echo htmlspecialchars("f" . $num . "_" . $field["name"]); ?>" name="<?php echo htmlspecialchars($field["name"]); ?>" value="<?php echo htmlspecialchars($field["value"]); ?>" />
<?php
break;
}
case "password":
{
if ($autofocus === false) $autofocus = htmlspecialchars("f" . $num . "_" . $field["name"]);
?>
<input class="text" type="password" id="<?php echo htmlspecialchars("f" . $num . "_" . $field["name"]); ?>" name="<?php echo htmlspecialchars($field["name"]); ?>" value="<?php echo htmlspecialchars($field["value"]); ?>" />
<?php
break;
}
case "checkbox":
{
if ($autofocus === false) $autofocus = htmlspecialchars("f" . $num . "_" . $field["name"]);
?>
<input class="checkbox" type="checkbox" id="<?php echo htmlspecialchars("f" . $num . "_" . $field["name"]); ?>" name="<?php echo htmlspecialchars($field["name"]); ?>" value="<?php echo htmlspecialchars($field["value"]); ?>" <?php if (isset($field["check"]) && $field["check"]) echo "checked"; ?> />
<label for="<?php echo htmlspecialchars("f" . $num . "_" . $field["name"]); ?>"><?php echo htmlspecialchars(BB_Translate($field["display"])); ?></label>
<?php
break;
}
case "select":
{
if ($autofocus === false) $autofocus = htmlspecialchars("f" . $num . "_" . $field["name"]);
if (!isset($field["multiple"]) || $field["multiple"] !== true) $mode = "select";
else $mode = "checkbox";
if (!isset($field["select"])) $field["select"] = array();
else if (is_string($field["select"])) $field["select"] = array($field["select"] => true);
$idbase = htmlspecialchars("f" . $num . "_" . $field["name"]);
if ($mode == "checkbox")
{
$idnum = 0;
foreach ($field["options"] as $name => $value)
{
if (is_array($value))
{
foreach ($value as $name2 => $value2)
{
$id = $idbase . ($idnum ? "_" . $idnum : "");
?>
<input class="checkbox" type="checkbox" id="<?php echo $id; ?>" name="<?php echo htmlspecialchars($field["name"]); ?>[]" value="<?php echo htmlspecialchars($name2); ?>"<?php if (isset($field["select"][$name2])) echo " checked"; ?> />
<label for="<?php echo $id; ?>"><?php echo htmlspecialchars(BB_Translate($name)); ?> - <?php echo ($value2 == "" ? " " : htmlspecialchars(BB_Translate($value2))); ?></label><br />
<?php
$idnum++;
}
}
else
{
$id = $idbase . ($idnum ? "_" . $idnum : "");
?>
<input class="checkbox" type="checkbox" id="<?php echo $id; ?>" name="<?php echo htmlspecialchars($field["name"]); ?>[]" value="<?php echo htmlspecialchars($name); ?>"<?php if (isset($field["select"][$name])) echo " checked"; ?> />
<label for="<?php echo $id; ?>"><?php echo ($value == "" ? " " : htmlspecialchars(BB_Translate($value))); ?></label><br />
<?php
$idnum++;
}
}
}
else
{
?>
<select id="<?php echo $idbase; ?>" name="<?php echo htmlspecialchars($field["name"]) . (isset($field["multiple"]) && $field["multiple"] === true ? "[]" : ""); ?>"<?php if (isset($field["multiple"]) && $field["multiple"] === true) echo " multiple"; ?>>
<?php
foreach ($field["options"] as $name => $value)
{
if (is_array($value))
{
?>
<optgroup label="<?php echo htmlspecialchars($name); ?>">
<?php
foreach ($value as $name2 => $value2)
{
?>
<option value="<?php echo htmlspecialchars($name2); ?>"<?php if (isset($field["select"][$name2])) echo " selected"; ?>><?php echo ($value2 == "" ? " " : htmlspecialchars(BB_Translate($value2))); ?></option>
<?php
}
?>
</optgroup>
<?php
}
else
{
?>
<option value="<?php echo htmlspecialchars($name); ?>"<?php if (isset($field["select"][$name])) echo " selected"; ?>><?php echo ($value == "" ? " " : htmlspecialchars(BB_Translate($value))); ?></option>
<?php
}
}
?>
</select>
<?php
}
break;
}
case "textarea":
{
if ($autofocus === false) $autofocus = htmlspecialchars("f" . $num . "_" . $field["name"]);
?>
<div class="textareawrap"><textarea class="text" id="<?php echo htmlspecialchars("f" . $num . "_" . $field["name"]); ?>" name="<?php echo htmlspecialchars($field["name"]); ?>" rows="5" cols="50"><?php echo htmlspecialchars($field["value"]); ?></textarea></div>
<?php
break;
}
case "table":
{
$order = isset($field["order"]) && (isset($options["submit"]) || (isset($options["useform"]) && $options["useform"])) ? $field["order"] : "";
?>
<table id="<?php echo htmlspecialchars("f" . $num . "_" . (isset($field["name"]) ? $field["name"] : "table")); ?>">
<tr class="head<?php if ($order != "") echo " nodrag nodrop"; ?>">
<?php
if ($order != "")
{
?>
<th><?php echo htmlspecialchars(BB_Translate($order)); ?></th>
<?php
}
foreach ($field["cols"] as $col)
{
?>
<th><?php echo htmlspecialchars(BB_Translate($col)); ?></th>
<?php
}
?>
</tr>
<?php
$num2 = 0;
foreach ($field["rows"] as $row)
{
?>
<tr id="<?php echo htmlspecialchars("f" . $num . "_" . (isset($field["name"]) ? $field["name"] : "table") . "_" . $num2); ?>" class="row<?php if ($num2 % 2) echo " altrow"; ?>">
<?php
if ($order != "")
{
?>
<td class="draghandle"> </td>
<?php
}
foreach ($row as $col)
{
?>
<td><?php echo $col; ?></td>
<?php
}
?>
</tr>
<?php
$num2++;
}
?>
</table>
<?php
if ($order != "")
{
?>
<script type="text/javascript">
InitPropertiesTableDragAndDrop('<?php echo BB_JSSafe("f" . $num . "_" . (isset($field["name"]) ? $field["name"] : "table")); ?>');
</script>
<?php
}
break;
}
case "custom":
{
echo $field["value"];
break;
}
}
if (isset($field["desc"]) && $field["desc"] != "")
{
?>
<div class="formitemdesc"><?php echo htmlspecialchars(BB_Translate($field["desc"])); ?></div>
<?php
}
else if (isset($field["htmldesc"]) && $field["htmldesc"] != "")
{
?>
<div class="formitemdesc"><?php echo BB_Translate($field["htmldesc"]); ?></div>
<?php
}
?>
</div>
<?php
}
?>
</div>
<?php
}
if (isset($options["submit"]))
{
?>
<div class="formsubmit">
<input class="submit" type="submit" value="<?php echo htmlspecialchars(BB_Translate($options["submit"])); ?>" />
</div>
<?php
}
if (isset($options["submit"]) || (isset($options["useform"]) && $options["useform"]))
{
?>
</form>
<?php
}
?>
</div>
<?php
if (isset($options["focus"]) && (is_string($options["focus"]) || ($options["focus"] === true && $autofocus !== false)))
{
?>
<script type="text/javascript">
$('#<?php echo BB_JSSafe(is_string($options["focus"]) ? $options["focus"] : $autofocus); ?>').focus();
</script>
<?php
}
}
function BB_PropertyFormError($message)
{
BB_RunPluginActionInfo("pre_bb_propertyformerror", $message);
?>
<div class="error"><?php echo htmlspecialchars(BB_Translate($message)); ?></div>
<?php
exit();
}
function BB_PropertyFormLoadError($message, $alt = false)
{
BB_RunPluginActionInfo("pre_bb_propertyformloaderror", $message);
?>
<div class="error"><?php echo htmlspecialchars(BB_Translate($message)); ?></div>
<script type="text/javascript">
CloseProperties<?php if ($alt) echo "2"; ?>();
</script>
<?php
exit();
}
// A couple oddball bits of functionality.
$bb_def_extmap = array(
".php" => array("edit" => "ea", "syntax" => "php"),
".css" => array("edit" => "ea", "syntax" => "css"),
".scss" => array("edit" => "ea", "syntax" => "scss"),
".js" => array("edit" => "ea", "syntax" => "js"),
".html" => array("edit" => "ea", "syntax" => "html"),
".htm" => array("edit" => "ea", "syntax" => "html"),
".xhtml" => array("edit" => "ea", "syntax" => "html"),
".xml" => array("edit" => "ea", "syntax" => "xml"),
".rss" => array("edit" => "ea", "syntax" => "rss"),
".svg" => array("edit" => "ea", "syntax" => "svg"),
".txt" => array("edit" => "ea", "syntax" => "text"),
".cfm" => array("edit" => "ea", "syntax" => "coldfusion"),
".cfml" => array("edit" => "ea", "syntax" => "coldfusion"),
".java" => array("edit" => "ea", "syntax" => "java"),
".py" => array("edit" => "ea", "syntax" => "python"),
".rb" => array("edit" => "ea", "syntax" => "ruby"),
".rbx" => array("edit" => "ea", "syntax" => "ruby"),
".rhtml" => array("edit" => "ea", "syntax" => "ruby"),
".pl" => array("edit" => "ea", "syntax" => "perl"),
".sql" => array("edit" => "ea", "syntax" => "sql"),
".cpp" => array("edit" => "ea", "syntax" => "cpp"),
".c" => array("edit" => "ea", "syntax" => "c"),
".cs" => array("edit" => "ea", "syntax" => "csharp"),
".vb" => array("edit" => "ea", "syntax" => "vb"),
".vbs" => array("edit" => "ea", "syntax" => "vb"),
".ml" => array("edit" => "ea", "syntax" => "ocaml"),
".bas" => array("edit" => "ea", "syntax" => "basic"),
".pas" => array("edit" => "ea", "syntax" => "pascal")
);
function BB_FileExplorer_ReplaceStr($find, $replace, $str)
{
return str_replace(array("%%HTML_" . $find . "%%", "%%HTML_JS_" . $find . "%%"), array(htmlspecialchars($replace), htmlspecialchars(BB_JSSafe($replace))), $str);
}
function BB_FileExplorer_GetActionStr($dir, $file, $wid = "")
{
global $editmap, $extmap;
$pos = strrpos($file, ".");
if ($pos === false) return "";
$ext = substr($file, $pos);
if (!isset($extmap[$ext]) || !isset($extmap[$ext]["edit"]) || !isset($editmap[$extmap[$ext]["edit"]])) return "";
$data = $editmap[$extmap[$ext]["edit"]];
$result = $data[0];
$result = BB_FileExplorer_ReplaceStr("DIR", $dir, $result);
$result = BB_FileExplorer_ReplaceStr("FILE", $file, $result);
$result = BB_FileExplorer_ReplaceStr("LOADTOKEN", BB_CreateSecurityToken("bb_main_edit_site_opt_file_explorer_edit_load", $wid, array($dir . "/" . $file)), $result);
$result = BB_FileExplorer_ReplaceStr("SAVETOKEN", BB_CreateSecurityToken("bb_main_edit_site_opt_file_explorer_edit_save", $wid, array($dir . "/" . $file)), $result);
$opts = explode(",", $data[1]);
foreach ($opts as $opt)
{
$result = BB_FileExplorer_ReplaceStr($opt, (isset($extmap[$ext][$opt]) ? $extmap[$ext][$opt] : ""), $result);
}
return $result;
}
BB_RunPluginAction("init");
if ($_REQUEST["bb_action"] == "bb_main_edit")
{
header("Content-Type: text/html; charset=UTF-8");
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><?php echo BB_Translate("Loading..."); ?></title>
<link rel="stylesheet" href="<?php echo htmlspecialchars(ROOT_URL); ?>/<?php echo htmlspecialchars(SUPPORT_PATH); ?>/css/mainedit.css" type="text/css" media="all" />
<?php BB_PreMainJS(); ?>
<script type="text/javascript">
var Gx__PageInfo = {
'menu_token' : '<?php echo BB_JSSafe(BB_CreateSecurityToken("bb_main_edit_menu")); ?>',
'mainviewinfo_token' : '<?php echo BB_JSSafe(BB_CreateSecurityToken("bb_main_edit_mainviewinfo")); ?>',
'mainviewinfo_notify' : <?php echo (isset($_REQUEST["notify"]) ? (int)$_REQUEST["notify"] : -1); ?>,
'mainviewinfo_profile' : '<?php echo BB_JSSafe(htmlspecialchars($bb_profile)); ?>',
'user' : '<?php echo BB_JSSafe(htmlspecialchars($bb_account["user"])); ?>',
'type' : '<?php echo BB_JSSafe(htmlspecialchars($bb_account["type"])); ?>',
'group' : '<?php echo BB_JSSafe(htmlspecialchars($bb_account["group"])); ?>',
'expire' : <?php echo $bb_session["expire"] - time(); ?>,
'start' : new Date()
};
</script>
<script type="text/javascript" src="<?php echo htmlspecialchars(ROOT_URL); ?>/<?php echo htmlspecialchars(SUPPORT_PATH); ?>/jquery-1.11.0<?php echo (defined("DEBUG_JS") ? "" : ".min"); ?>.js"></script>
<script type="text/javascript" src="<?php echo htmlspecialchars(ROOT_URL); ?>/<?php echo htmlspecialchars(SUPPORT_PATH); ?>/js/mainedit.js"></script>
</head>
<body>
<div class="pagewrap">
<div class="contentwrap">
<div class="colmask">
<div class="colright">
<div class="col1wrap">
<div class="col1">
<div class="col1inner">
<div class="maincontent">
<div id="mainprops"></div>
<div id="mainprops2"></div>
<div id="loadcondscripts"></div>
<div id="contenteditor"></div>
<div id="fileeditor"></div>
<div id="mainviewwrap">
<div id="navbutton"><?php echo htmlspecialchars(BB_Translate("Menu")); ?></div><div id="navdropdown"><div class="leftnav"></div></div><div id="mainviewinfo"></div>
<iframe id="mainview" src="<?php echo BB_GetRequestURLBase(); ?>?bb_action=bb_main_edit_view&lang=<?php echo urlencode($bb_pref_lang); ?><?php if ($bb_revision_num > -1) echo "&bb_revnum=" . $bb_revision_num; ?><?php if ($bb_profile != "") echo "&bb_profile=" . urlencode($bb_profile); ?>&bbt=<?php echo htmlspecialchars(BB_CreateSecurityToken("bb_main_edit_view")); ?>" width="100%" height="1" frameborder="0"></iframe>
<div id="sessioninfo"></div>
</div>
</div>
</div>
</div>
</div>
<div class="col2"><div class="leftnav"></div></div>
</div>
</div>
</div>
<div class="stickycol"></div>
</div>
</body>
</html>
<?php
}
else if ($_REQUEST["bb_action"] == "bb_main_edit_mainviewinfo")
{
BB_RunPluginAction("pre_bb_main_edit_mainviewinfo");
// Extensions check.
BB_LoadExtensionsCache();
BB_UpdateExtensionsCache();
if (count($bb_extensions_info["vulnerabilities"])) echo "<div id=\"mainviewinfo_vulnerabilities\">" . BB_HTMLPurify(implode("<br /><br />", $bb_extensions_info["vulnerabilities"])) . "</div>";
if (count($bb_extensions_info["updates"])) echo "<div id=\"mainviewinfo_updates\">" . BB_HTMLPurify(implode("<br /><br />", $bb_extensions_info["updates"])) . "</div>";
echo ($bb_revision_writeable ? "" : BB_Translate("<b>[Read Only]</b> "));
echo htmlspecialchars(BB_Translate(BB_GetIANADesc($bb_pref_lang)));
echo ($bb_pref_lang == $bb_page["defaultlang"] ? BB_Translate(" [default]") : "");
echo ($bb_profile != "" ? htmlspecialchars(BB_Translate(", " . $bb_profiles[$bb_profile])) : "");
if ($bb_revision_num < 0) echo ", <a href=\"" . htmlspecialchars(BB_GetFullRequestURLBase("http") . "?lang=" . urlencode($bb_pref_lang)) . "\">" . BB_Translate("Live Page") . "</a>";
else echo BB_Translate(", Revision #%d, %s, Reason: %s | %s", $bb_revision_num, ($bb_revision[0] == "" ? BB_Translate("<i>[Root]</i>") : htmlspecialchars($bb_revision[0])), htmlspecialchars($bb_revision[4]), "<a href=\"" . htmlspecialchars(BB_GetFullRequestURLBase("http") . "?lang=" . urlencode($bb_pref_lang)) . "\">" . BB_Translate("Live Page") . "</a>");
if (isset($_REQUEST["notify"]))
{
require_once "translate.php";
if (isset($bb_translate_notify[(int)$_REQUEST["notify"]]))
{
$entry = $bb_translate_notify[(int)$_REQUEST["notify"]];
echo BB_Translate("<br />%s, %s, %s => %s, %s", htmlspecialchars($entry[0]), BB_FormatTimestamp($entry[1]), htmlspecialchars(BB_Translate(BB_GetIANADesc($entry[4], true, true))), htmlspecialchars(BB_Translate(BB_GetIANADesc($entry[5], true, true))), htmlspecialchars($entry[6]));
}
}
BB_RunPluginAction("post_bb_main_edit_mainviewinfo");
}
else if ($_REQUEST["bb_action"] == "bb_main_edit_view")
{
BB_RunPluginAction("pre_bb_main_edit_view");
if ($bb_page["redirect"] != "") header("Location: " . $bb_page["redirect"]);
else BB_ProcessPage(false, true, false);
BB_RunPluginAction("post_bb_main_edit_view");
}
else if ($_REQUEST["bb_action"] == "bb_main_edit_menu")
{
BB_RunPluginAction("pre_bb_main_edit_menu");
?>
<div class="menu">
<div class="title"><?php echo BB_Translate("Page Options"); ?></div>
<?php
BB_RunPluginAction("bb_main_edit_menu_pre_page_options");
echo BB_CreatePropertiesLink(BB_Translate("Edit Properties"), "bb_main_edit_page_opt_properties");
if (count($bb_profiles) > 1) echo BB_CreatePropertiesLink(BB_Translate("View Cache Profiles"), "bb_main_edit_page_opt_view_cache_profiles");
echo BB_CreatePropertiesLink(BB_Translate("Create New Branch"), "bb_main_edit_page_opt_create_branch");
if ($bb_revision_num > -1)
{
if ($bb_revision_writeable && $bb_revision[0] != "") echo BB_CreatePropertiesLink(BB_Translate("Close Branch"), "bb_main_edit_page_opt_close_branch");
echo BB_CreatePropertiesLink(BB_Translate("Copy To Live Page"), "bb_main_edit_page_opt_overwrite_live_page");
}
echo BB_CreatePropertiesLink(BB_Translate("Create New Revision"), "bb_main_edit_page_opt_create_revision");
echo BB_CreatePropertiesLink(BB_Translate("View Revisions"), "bb_main_edit_page_opt_view_revisions");
if ($bb_revision_num < 0) echo BB_CreatePropertiesLink(BB_Translate("Notify Translators"), "bb_main_edit_page_opt_ping_translation");
echo BB_CreatePropertiesLink(BB_Translate("Create New Translation"), "bb_main_edit_page_opt_create_translation");
echo BB_CreatePropertiesLink(BB_Translate("View Translations"), "bb_main_edit_page_opt_view_translations");
BB_RunPluginAction("bb_main_edit_menu_post_page_options");
?>
</div>
<div class="menu">
<div class="title"><?php echo BB_Translate("Site Options"); ?></div>
<?php
BB_RunPluginAction("bb_main_edit_menu_pre_site_options");
echo BB_CreatePropertiesLink(BB_Translate("File Explorer"), "bb_main_edit_site_opt_file_explorer");
echo BB_CreatePropertiesLink(BB_Translate("View Notifications"), "bb_main_edit_site_opt_view_translation_notifications");
echo BB_CreatePropertiesLink(BB_Translate("Edit Profile"), "bb_main_edit_site_opt_profile");
if ($bb_account["type"] == "dev")
{
echo BB_CreatePropertiesLink(BB_Translate("Create New Account"), "bb_main_edit_site_opt_create_account");
if (count($bb_accounts["users"]) > 1) echo BB_CreatePropertiesLink(BB_Translate("Delete an Account"), "bb_main_edit_site_opt_delete_account");
if (function_exists("zip_open")) echo BB_CreatePropertiesLink(BB_Translate("Manage Extensions"), "bb_main_edit_site_opt_manage_extensions");
echo BB_CreatePropertiesLink(BB_Translate("Create New Widget"), "bb_main_edit_site_opt_create_widget");
echo BB_CreatePropertiesLink(BB_Translate("Delete Widget"), "bb_main_edit_site_opt_delete_widget");
}
echo BB_CreatePropertiesLink(BB_Translate("Flush Cache"), "bb_main_edit_site_opt_flush_cache", array(), "", true);
echo BB_CreatePropertiesLink(BB_Translate("Logout"), "bb_main_edit_site_opt_logout");
BB_RunPluginAction("bb_main_edit_menu_post_site_options");
?>
</div>
<div class="menu">
<div class="title">Barebones CMS</div>
<?php
BB_RunPluginAction("bb_main_edit_menu_pre_support_options");
?>
<a href="http://barebonescms.com/" target="_blank"><?php echo BB_Translate("Homepage"); ?></a>
<a style="color: #008800;" href="http://barebonescms.com/donate/" target="_blank" title="Don't be a cheapskate. Support the author to keep Barebones CMS development going."><?php echo BB_Translate("Donate"); ?></a>
<a href="http://barebonescms.com/forums/" target="_blank"><?php echo BB_Translate("Forums"); ?></a>
<?php
BB_RunPluginAction("bb_main_edit_menu_post_support_options");
?>
</div>
<?php
BB_RunPluginAction("post_bb_main_edit_menu");
}
else if ($_REQUEST["bb_action"] == "bb_main_edit_page_opt_properties_submit")
{
BB_RunPluginAction("pre_bb_main_edit_page_opt_properties_submit");
if (!BB_IsMemberOfPageGroup("_p")) BB_PropertyFormError("You do not have permissions to edit the page properties.");
if ($bb_account["type"] == "content")
{
if (!$bb_revision_writeable) BB_PropertyFormError("Page properties are not writeable. This can occur when a new revision within an existing branch is created while editing an editable revision.");
$bb_langpage["title"] = $_REQUEST["title"];
$bb_langpage["metadesc"] = $_REQUEST["metadesc"];
BB_SaveLangPage($bb_revision_num);
BB_UpdateSitemaps();
}
else if ($bb_account["type"] == "dev" || $bb_account["type"] == "design")
{
$bb_page["redirect"] = $_REQUEST["redirect"];
$bb_page["cachetime"] = (int)$_REQUEST["cachetime"];
if ($bb_page["cachetime"] < 0) $bb_page["cachetime"] = -1;
$bb_page["easyedit"] = ($_REQUEST["easyedit"] == "enable");
$bb_page["sitemap"] = ($_REQUEST["sitemap"] == "include");
$bb_page["sitemappriority"] = $_REQUEST["sitemappriority"];
$bb_page["doctype"] = $_REQUEST["doctype"];
$bb_page["metarobots"] = (isset($_REQUEST["metarobots"]) && is_array($_REQUEST["metarobots"]) ? implode(",", $_REQUEST["metarobots"]) : "");
$bb_page["perms"]["_p"] = array();
if (isset($_REQUEST["perms"]) && is_array($_REQUEST["perms"]))
{
foreach ($_REQUEST["perms"] as $group) $bb_page["perms"]["_p"][$group] = true;
}
if ($bb_revision_writeable)
{
$bb_langpage["title"] = $_REQUEST["title"];
$bb_langpage["metadesc"] = $_REQUEST["metadesc"];
BB_SaveLangPage($bb_revision_num);
}
BB_SavePage();
BB_UpdateSitemaps();
}
BB_DeletePageCache();
?>
<div class="success"><?php echo htmlspecialchars(BB_Translate("Options saved.")); ?></div>
<script type="text/javascript">
ReloadIFrame();
CloseProperties();
</script>
<?php
BB_RunPluginAction("post_bb_main_edit_page_opt_properties_submit");
}
else if ($_REQUEST["bb_action"] == "bb_main_edit_page_opt_properties")
{
BB_RunPluginAction("pre_bb_main_edit_page_opt_properties");
if (!BB_IsMemberOfPageGroup("_p")) BB_PropertyFormLoadError("You do not have permissions to edit the page properties.");
if ($bb_account["type"] == "content")
{
if (!$bb_revision_writeable) BB_PropertyFormLoadError("Page properties are not writeable.");
$options = array(
"title" => "Edit Properties",
"desc" => "Edit the page properties.",
"fields" => array(
array(
"title" => "Page Title",
"type" => "text",
"name" => "title",
"value" => $bb_langpage["title"],
"desc" => "The localized title of this page."
),
array(
"title" => "Meta Description",
"type" => "text",
"name" => "metadesc",
"value" => $bb_langpage["metadesc"],
"desc" => "The localized HTML meta description tag. Used by some search engines."
)
),
"submit" => "Save",
"focus" => true
);
BB_RunPluginAction("bb_main_edit_page_opt_properties_content_lang_options");
BB_PropertyForm($options);
}
else if ($bb_account["type"] == "dev" || $bb_account["type"] == "design")
{
$doctypes = array();
foreach ($bb_doctypes as $doctype => $html) $doctypes[$doctype] = $doctype;
$metarobots = array();
foreach (explode(",", $bb_page["metarobots"]) as $val) $metarobots[$val] = true;
$options = array(
"title" => "Edit Properties",
"desc" => "Edit the page properties.",
"fields" => array(
array(
"title" => "Redirect Page",
"type" => "text",
"name" => "redirect",
"value" => $bb_page["redirect"],
"desc" => "Redirect this page elsewhere. Prefer redirection over deletion to avoid 404 errors."
),
array(
"title" => "Cache Time",
"type" => "text",
"name" => "cachetime",
"value" => $bb_page["cachetime"],
"desc" => "The amount of time to cache this page in seconds."
),
array(
"title" => "Easy Edit",
"type" => "select",
"name" => "easyedit",
"options" => array(
"enable" => "Enable",
"disable" => "Disable"
),
"select" => ($bb_page["easyedit"] ? "enable" : "disable"),
"desc" => "Easy Edit is a small piece of Javascript that makes it easy to enter this editor."
),
array(
"title" => "XML Sitemap",
"type" => "select",
"name" => "sitemap",
"options" => array(
"include" => "Include",
"exclude" => "Exclude"
),
"select" => ($bb_page["sitemap"] ? "include" : "exclude"),
"desc" => "XML Sitemaps make it easy for search engines to find all of your content."
),
array(
"title" => "XML Sitemap Priority",
"type" => "select",
"name" => "sitemappriority",
"options" => array(
"high" => "High",
"normal" => "Normal",
"low" => "Low"