-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPageLock.php
More file actions
752 lines (591 loc) · 28.7 KB
/
PageLock.php
File metadata and controls
752 lines (591 loc) · 28.7 KB
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
<?php
/*
Plugin Name: Page Lock
Description: With this plugin you can limit changes in page options, deleting, creating selected pages.
Version: 1.21
Author: Michał Gańko
Author URI: http://flexphperia.net
*/
# get correct id for plugin
$thisfile=basename(__FILE__, ".php");
# register plugin
register_plugin(
$thisfile,
'Page Lock',
'1.21',
'Michał Gańko',
'http://flexphperia.net',
'With this plugin you can limit changes in page options, deleting, creating selected pages.',
'plugins',
'page_lock_admin_tab'
);
if (!is_frontend()) { //only on backend
add_action('edit-extras','page_lock_on_edit_extras');
add_action('pages-main','page_lock_on_pages_main');
add_action('header','page_lock_on_header');
add_action('footer','page_lock_on_footer');
add_action('plugins-sidebar', 'createSideMenu', [$thisfile, 'Configure Page Lock']);
//include special pages class
@include_once(GSPLUGINPATH.'i18n_specialpages/specialpages.class.php');
$pl_i18nSecurityStore = ['normal' => [], 'special' => []]; //used to store some data
$pl_spExists = class_exists('I18nSpecialPages'); //is special pages plugin exists or not (might be disabled but uploaded)
}
$pl_currFile = strtolower(basename($_SERVER['PHP_SELF'])); //currently loadded file
//delete lock security check
if ($pl_currFile =='deletefile.php') {
if (isset($_GET['id'])) {
$id = $_GET['id'];
$settings = page_lock_get_settings();
if ($settings->delete_lock && in_array($id , $settings->delete_slugs)){
die('Page Lock plugin: delete lock!');
}
}
}
//page options lock security check and creating page lock security check
if ($pl_currFile =='changedata.php' && isset($_POST['submitted'])) {
$settings = page_lock_get_settings();
$spExtraCheck = $pl_spExists && $settings->special_pages_security;
//if we are here so we can create page it might be typical page or special one
if ($spExtraCheck && isset($_POST['post-special']) && !empty($_POST['post-special'])){
//we are sure that this is special one
$spDef = I18nSpecialPages::getSettings($_POST['post-special']);
if (empty($spDef)) //special type not found
die('Page Lock plugin special pages security check: special type settings not found!');
if ($spDef['template'] && $_POST['post-template'] != $spDef['template'])
die('Page Lock plugin special pages security check: template change!');
if ($spDef['parent'] && $_POST['post-parent'] != $spDef['parent'])
die('Page Lock plugin special pages security check: parent change!');
}
if ( isset($_POST['existing-url']) ){ //if editing currently existing page
$oldSlug = $_POST['existing-url'];
$newSlug = $_POST['post-id'];
$checkParams = in_array($oldSlug , $settings->options_slugs); //we believe that some checkboxes are checked
if ($checkParams || $spExtraCheck){
$file = GSDATAPAGESPATH . $oldSlug . '.xml';
$oldData = getXML($file);
if ($checkParams){
if ($settings->slug_lock && $oldSlug != $newSlug){
die('Page Lock plugin: slug lock!');
}
if ($settings->template_lock && $_POST['post-template'] != (string)$oldData->template){
die('Page Lock plugin: template lock!');
}
//i18n navigation support, when saving translated page skip checking private and parent coz it's emptied by i18n nav plugin
if (strpos($newSlug,'_') === false){
if ($settings->visibility_lock && $_POST['post-private'] != (string)$oldData->private){
die('Page Lock plugin: visibility lock!');
}
if ($settings->parent_lock && $_POST['post-parent'] != (string)$oldData->parent){
die('Page Lock plugin: parent lock!');
}
}
}
//additional check for special pages, simply compare value from old data and new data
if ($spExtraCheck){
if (isset($_POST['post-special']) && !empty($_POST['post-special']) != (string)$oldData->special)
die('Page Lock plugin special pages security check: special type change!');
}
}
}
else if (!isset($_POST['existing-url'])){ //if creating new page
if (($settings->create_lock && !$settings->special_pages_enabled) ||
($settings->create_lock && $settings->special_pages_enabled && !in_array($_POST['post-special'] , $settings->special_types))){
die('Page Lock plugin: create page lock!');
}
}
}
//create lock, cloning page security check
if ($pl_currFile =='pages.php') {
if ( @$_GET['action'] == 'clone' ) {
$id = $_GET['id'];
$file = GSDATAPAGESPATH . $id .".xml";
$oldData = getXML($file);
if ($oldData){
$settings = page_lock_get_settings();
if (($settings->create_lock && !$settings->special_pages_enabled) || (
$settings->create_lock && $settings->special_pages_enabled && !in_array((string)$oldData->special , $settings->special_types))){
die('Page Lock plugin: create pages lock!');
}
}
}
}
function page_lock_admin_tab() {
if (isset($_POST['options_slugs'])){ //is post
$visibility_lock = !empty($_POST['visibility_lock'])?1:0;
$template_lock = !empty($_POST['template_lock'])?1:0;
$parent_lock = !empty($_POST['parent_lock'])?1:0;
$slug_lock = !empty($_POST['slug_lock'])?1:0;
$preview_lock = !empty($_POST['preview_lock'])?1:0;
$special_browse_remove = !empty($_POST['special_browse_remove'])?1:0;
$delete_lock = !empty($_POST['delete_lock'])?1:0;
$create_lock = !empty($_POST['create_lock'])?1:0;
$special_pages_enabled = !empty($_POST['special_pages_enabled'])?1:0;
$special_pages_security = !empty($_POST['special_pages_security'])?1:0;
$success = page_lock_save_settings( $visibility_lock,
$template_lock,
$parent_lock,
$slug_lock,
$_POST['options_slugs'],
$preview_lock,
$special_browse_remove,
$delete_lock,
$_POST['delete_slugs'],
$create_lock,
$special_pages_enabled,
$_POST['special_types'],
$special_pages_security
);
}
$settings = page_lock_get_settings();
require_once('PageLock/views/configuration.html');
}
//removes private button from i18n_navigation Edit Navigation Structure option
function page_lock_on_header(){
global $pl_currFile, $pagesArray, $pl_spExists, $pl_i18nSecurityStore;
if ($pl_currFile == 'load.php' && @$_GET['id'] == 'PageLock'){
?>
<link rel="stylesheet" href="../plugins/PageLock/css/configuration.css" />
<?php
return;
}
$settings = page_lock_get_settings();
$spExtraCheck = $pl_spExists && $settings->special_pages_security;
$script = '<script>$( document ).ready(function() {';
//remove link for creating new page in support tab
if ($pl_currFile == 'support.php') {
echo '<style type="text/css">#maincontent{display:none}</style>';
if ($settings->create_lock){
$script .= '$(\'a[href="edit.php"]\').parent(\'li\').remove();';
}
$script .= '$(\'#maincontent\').show();';
}
if ($pl_currFile =='pages.php' || $pl_currFile =='edit.php' || $pl_currFile =='load.php' ) {
echo '<style type="text/css">#sidebar{display:none;}</style>'; //hide sidebar for changes
if ($settings->special_browse_remove){ //remove browse button
$script .= '$(\'#sidebar li a[href="load.php?id=i18n_specialpages&pages"]\').closest(\'li\').remove(); ';
}
if ($settings->create_lock){
$script .= '$(\'#sb_newpage\').remove();';
if (!$settings->special_pages_enabled){ //remove Create special page on sidebar
$script .= '$(\'#sidebar li a[href="load.php?id=i18n_specialpages&create"]\').remove();';
}
}
$script .= '$(\'#sidebar\').show();'; //show sidebar after changes
}
if ($pl_currFile =='load.php') {
//i18n Multilevel navigation plugin
if (@$_GET['id'] == 'i18n_navigation'){
$len = count($settings->options_slugs);
echo '<style type="text/css">#maincontent{display:none;}</style>';
if ($settings->visibility_lock && $len){
foreach ($settings->options_slugs as $value)
{
$script .='$(\'#editnav tr#tr-'.$value.' a.togglePrivate\').remove();';
$script .='if ($(\'#editnav tr#tr-'.$value.'\').find(\'input[name$=private]\').val() == \'Y\'){
//if page is private and private locked then do not allow to change menu status from here
//coz clicking on Menu status button will dispatch handler that unprivates page
$(\'#editnav tr#tr-'.$value.' a.toggleMenu\').remove();
};';
}
}
//removes all arrows for pages that has parent locked, special and normal ones
$parentLockedSlugs = [];
if ($settings->parent_lock && $len){ //normal pages
$parentLockedSlugs = array_merge($parentLockedSlugs, $settings->options_slugs);
}
if ($spExtraCheck){ //special pages
//create pagesArray its not ready , order off added hooks matters. this plugin added hook before "caching_function.php" did this
getPagesXmlValues(true);
//find what special slugs are locked
$spDef = I18nSpecialPages::getSettings(null); //get all special pages definitions
$specialSlugs = [];
foreach ($pagesArray as $key => $value){
if ( isset($value['special']) && !empty($value['special']) ){
if (!isset($spDef[$value['special']])) //special type not found
die('Page Lock plugin special pages security check: special type settings not found!');
if ( $spDef[$value['special']]['parent'] )
$specialSlugs[] = $value['url'];
}
}
$parentLockedSlugs = array_merge($parentLockedSlugs, $specialSlugs);
}
if (count($parentLockedSlugs)){
$script .= '
var parentLockedIds = ['.'"'.implode('","', $parentLockedSlugs).'"'.'];
$(\'#editnav tbody tr[id]\').each(function(){
var $tr = $(this),
slug = $tr.attr(\'id\').substr(3);
if ($.inArray(slug, parentLockedIds) != -1){
$tr.find(\'a.moveRight,a.moveLeft\').remove(); //removes arrows
};
});
var $line = $(\'<div class="pl_line" style="position: absolute; height: 1px; width: 100%; border-top: 2px dotted #CF3805; z-index: 9999;"></div>\');
//function used to show lines
var showLines = function($row, $draggedRow, onBottom){
var id = $draggedRow.attr(\'id\').substr(3),
thisLevel = getLevel($draggedRow); //level of currently dragged item
if ($.inArray(id, parentLockedIds) == -1)
return; //continue loop
if (getLevel($row) < thisLevel ){ //if row level is lower then dragged one = its parent
var top = $row.find(\'td:first\').offset().top, //find top
$cont = $(\'#maincontent .main\'),
targetTop = onBottom ? top : top + ($row.find(\'td:first\').outerHeight(true)); //on bottom or top border
$line.width($cont.width() + \'px\'); //set width as table width
$line.css(\'top\', targetTop + \'px\').clone().appendTo($cont);
return false; //will break loop
}
};
//on sort start create some tips
$( "#editnav tbody" ).on( "sortstart", function( event, ui ) {
var $prevs = ui.item.prevAll(\'tr\'), //all previous
$nexts = ui.item.nextAll(\'tr\');
//find parent and show line
$prevs.each(function(){
return showLines($(this), ui.item);
});
//find next level and show line
$nexts.each(function(){
return showLines($(this), ui.item, true);
});
})
.on( "sortstop", function( event, ui ) {
$(\'.pl_line\').remove(); //remove lines
});
';
}
if ($settings->preview_lock){
$script .='$(\'#editnav tr td.secondarylink:last-child\').remove();';
}
$script .= '$(\'#maincontent\').show();';
//page options lock security check when saving data from Edit Navigation Structure
if (!empty($_POST['save'])){ //saving
if ($settings->visibility_lock){
for ($i=0; isset($_POST['page_'.$i.'_url']); $i++) {
$slug = $_POST['page_'.$i.'_url'];
if (in_array($slug , $settings->options_slugs)){
if ($_POST['page_'.$i.'_private'] != $pagesArray[$slug]['private'])
die('Page Lock plugin: private lock (i18n_navigation)!');
}
}
}
//if parent lock is enabled and opstion slugs exists, sotre old page data before 18n navigation will save
//used later in footer hook
//now $pagesArray has old data
if ( $spExtraCheck ){
foreach ($pagesArray as $key => $value){
//if its special, and this special has parent than store its original parent
if ( isset($value['special']) && !empty($value['special']) && in_array($value['url'], $specialSlugs) )
$pl_i18nSecurityStore['special'][$key] = $value['parent']; //stores old parent
}
}
if ( $settings->parent_lock && $len ){ //normal lock
foreach ($settings->options_slugs as $slug)
{
$pl_i18nSecurityStore['normal'][$slug] = $pagesArray[$slug]['parent']; //store parent if its slug is on locked pages
}
}
}
}
//i18n base plugin support, disables create page buttons
if (@$_GET['id'] == 'i18n_base') {
echo '<style type="text/css">#maincontent{display:none;}</style>';
if ($settings->create_lock){
if ($settings->special_pages_enabled){ //some specials are enabled
//find what is allowed for translating
$allowedSlugs = [];
foreach ($pagesArray as $key => $val){
if (strpos($key, '_') !== false) //find only default langague slugs
continue;
//has special?
if (isset($val['special'])){
if (in_array($val['special'] , $settings->special_types)){ //on allowed list, collect id
$allowedSlugs[] = $key;
}
}
}
//remove translation links only on not allowed special pages types
$script .= '
var pl_allowed_ids = ['.'"'.implode('","', $allowedSlugs).'"'.'],
pl_reg = new RegExp("edit\.php\\\?newid=([a-z0-9-]+)_.*&title", "i");
$(\'#editpages tbody tr\').each(function(){
var $tr = $(this),
$a = $tr.find(\'td a[href^="edit.php?newid="]\'), //not only in secondarylink td but also in delete class td
res = pl_reg.exec($a.attr(\'href\'));
if (!res || (res && $.inArray(res[1], pl_allowed_ids) == -1) ){
$a.remove();
}
});
';
}
else{ //remove all create buttons, no specials allowed
$script .= '$(\'#editpages tbody tr td a[href^="edit.php?newid="]\').remove();';
}
}
if ($settings->preview_lock){ //if preview lock
//title=blank attribute giving us knowledge that this is for sure preview link
$script .= '$(\'#editpages tr td.secondarylink a[target="_blank"]\').remove();';
}
if ($settings->special_browse_remove){ //remove browse button
$script .= '$(\'#sidebar li a[href="load.php?id=i18n_specialpages&pages"]\').closest(\'li\').remove(); ';
}
if ($settings->delete_lock){ //if delete lock activated, remove delete buttons
$len = count($settings->delete_slugs);
if ($len){
foreach ($settings->delete_slugs as $value)
{
$script .= '$(\'a.i18n-delconfirm[href^="deletefile.php?id='.$value.'&"]\').remove();';
}
}
}
$script .= '$(\'#maincontent\').show();';
}
//specialpages operations
if (@$_GET['id'] == 'i18n_specialpages') {
//hide content, wait untli js complete all deletions
echo '<style type="text/css">#maincontent{display:none}</style>';
if (isset($_GET['pages']) && isset($_GET['special'])){ //browsing pages by special type
if ($settings->preview_lock){ //if preview lock
$script .= '$(\'#editpages tr td.secondarylink a[target="_blank"]\').remove();'; //remove only that needed to remove
}
if ($settings->delete_lock){ //if delete lock activated, remove delete buttons
$len = count($settings->delete_slugs);
if ($len){
foreach ($settings->delete_slugs as $value)
{
$script .= '$(\'a[href^="deletefile.php?id='.$value.'&"]\').remove();';
}
}
}
if ($settings->create_lock && !$settings->special_pages_enabled){
$script .= '$(\'a[href="edit.php?special='.$_GET['special'].'"]\').remove();'; //bottom link
//remove create buttons when i18n base is activated
$script .= '$(\'#editpages tbody tr td.secondarylink a[href^="edit.php?newid="]\').remove();';
}
else if ($settings->create_lock && $settings->special_pages_enabled){
if ( !in_array($_GET['special'] , $settings->special_types) ){ //remove create page link bottom of page
$script .= '$(\'a[href="edit.php?special='.$_GET['special'].'"]\').remove();';
}
//remove create buttons when i18n base is activated
$script .= '
var pl_allowed = ['.'"'.implode('","', $settings->special_types).'"'.'],
pl_reg = /&metak=_special_(.+)%2C/;
$(\'#editpages tbody tr\').each(function(){
var $tr = $(this),
$a = $tr.find(\'td.secondarylink a[href^="edit.php?newid="]\'),
res = pl_reg.exec($a.attr(\'href\'));
if (!res || (res && $.inArray(res[1], pl_allowed) == -1) ){
$a.remove();
}
});
';
}
}
else if ( isset($_GET['pages']) ){ //show all available special types
if ($settings->create_lock){
if ($settings->special_pages_enabled){ //some specials are enabled
$script .= '
var pl_allowed = ['.'"'.implode('","', $settings->special_types).'"'.'];
$(\'#editspecial tbody tr\').each(function(){
var $tr = $(this),
$a = $tr.find(\'td a[href^="edit.php?special="]\');
if ($.inArray($a.attr(\'href\').replace("edit.php?special=", ""), pl_allowed) == -1 ){
$a.remove();
}
});
';
}
else{ //remove all create buttons, no specials allowed
$script .= '$(\'#editspecial tbody tr td a[href^="edit.php?special="]\').remove();';
}
}
}
else if ( isset($_GET['create']) ){ //Create New Special Page, list of special pages types
if ($settings->create_lock && $settings->special_pages_enabled){ //remove all rows that are not allowed
$script .= '
var pl_allowed = ['.'"'.implode('","', $settings->special_types).'"'.'];
$(\'#editspecial tbody tr\').each(function(){
var $tr = $(this),
$a = $tr.find(\'td a\');
if ( $.inArray($a.attr(\'href\').replace("edit.php?special=", ""), pl_allowed) == -1 ){
$tr.remove();
}
});
';
}
}
$script .= '$(\'#maincontent\').show();';
}
}
$script .= '});</script>';
echo $script;
}
function page_lock_on_footer(){
//i18n Multilevel navigation plugin securoty check for changing parent
//if pl_i18nSecurityStore not empty check should be applied
//now $pagesarray has new values
global $pl_i18nSecurityStore, $pagesArray;
if (@$_GET['id'] == 'i18n_navigation' && !empty($_POST['save']) && $pl_i18nSecurityStore) {
$normalWasChanged = false;
$specialWasChanged = false;
if (count($pl_i18nSecurityStore['normal'])){
foreach ($pl_i18nSecurityStore['normal'] as $slug => $oldParent)//get slugs from storage temporary
{
//compare old data and new data
if ($pagesArray[$slug]['parent'] != $oldParent){
$normalWasChanged = true;
}
}
}
if (count($pl_i18nSecurityStore['special'])){ //if there are any so this check is enabled in settings
foreach ($pl_i18nSecurityStore['special'] as $slug => $oldParent)//get special slugs from storage temporary
{
//compare old data and new data
if ($pagesArray[$slug]['parent'] != $oldParent){
$specialWasChanged = true;
}
}
}
if ($normalWasChanged || $specialWasChanged){
i18n_navigation_structure_undo();
$s = ['Page Lock plugin:'];
if ($normalWasChanged){
$s[] = 'parent lock (i18n_navigation)!';
}
if ($specialWasChanged){
$s[] = 'special pages parent lock (i18n_navigation)!';
}
//show info and refresh
die('<script>$( document ).ready(function() {alert(\''.implode('\n',$s).'\'); window.location = window.location.href; } );</script>');
}
}
}
//removes delete buttons from standard pages list
function page_lock_on_pages_main() {
$settings = page_lock_get_settings();
//hide content, wait untli js complete
echo '<style type="text/css">#maincontent{display:none}</style>';
$script = '<script>$( document ).ready(function() {';
//if on restriction list, disable delet ebutton on pages list
$len = count($settings->delete_slugs);
if ($settings->delete_lock && $len){
foreach ($settings->delete_slugs as $value)
{
$script .= '$(\'#editpages a.delconfirm[href^="deletefile.php?id='.$value.'&"]\').remove();';
}
}
if ($settings->preview_lock ){
$script .= '$(\'#editpages td.secondarylink\').remove();';
}
$script .= '$(\'#maincontent\').show();';
$script .= '});</script>';
echo $script;
}
//disables page option fields
function page_lock_on_edit_extras() {
global $url; //here is slug
$settings = page_lock_get_settings();
//hide content, wait untli js complete
echo '<style type="text/css">#maincontent{display:none}</style>';
$script = '<script>$( document ).ready(function() {';
//prepare page options
if (in_array($url , $settings->options_slugs)){
if ($settings->slug_lock){
$script .= '$("#post-id").attr("readonly", "readonly");';
}
if ($settings->visibility_lock){
$script .= '$("#post-private").attr("disabled", "disabled");';
}
if ($settings->parent_lock){
$script .= '$("#post-parent").attr("disabled", "disabled");';
}
if ($settings->template_lock){
$script .= '$("#post-template").attr("disabled", "disabled");';
}
//remove disabled attribute before submitting, for sending POST data
$script .= '
$(\'#editform\').bind(\'submit\', function() {
$(this).find(\'select\').removeAttr(\'disabled\');
});
';
}
//preview lock remov button
if ($settings->preview_lock){
$script .= '$("#metadata_toggle").prev("a").remove();';
}
//disable delete option from dropdown next to save button
if ($settings->delete_lock && in_array($url , $settings->delete_slugs)){
$script .= '$(\'li a[href^="deletefile.php?id='.$url.'&"]\').remove();';
}
global $id;
//disable clone option from dropdown next to save button
if ($settings->create_lock && $id){ //if editing existing page, not new page
global $data_edit; //SimpleXML to read from
if ($settings->special_pages_enabled && in_array((string)$data_edit->special , $settings->special_types)){
}
else{
$script .= '$(\'li a[href^="pages.php?id='.$url.'&action=clone"]\').remove();';
}
}
$script .= '$(\'#maincontent\').show();';
$script .= '});</script>'; //close script
echo $script;
}
//retrieves settings from xml
function page_lock_get_settings() {
$file = GSDATAOTHERPATH . 'pagelock.xml';
if (!file_exists($file)) {
page_lock_save_settings(); //create empty one
}
$data = getXML($file);
$settings = new stdClass();
$settings->visibility_lock = (bool) (string) $data->visibility_lock;
$settings->template_lock = (bool) (string) $data->template_lock;
$settings->parent_lock = (bool) (string) $data->parent_lock;
$settings->slug_lock = (bool) (string) $data->slug_lock;
$settings->options_slugs = (string)$data->options_slugs ? explode(',',(string)$data->options_slugs) : [];
$settings->preview_lock = (bool) (string) $data->preview_lock;
$settings->special_browse_remove = (bool) (string) $data->special_browse_remove;
$settings->delete_lock = (bool) (string) $data->delete_lock;
$settings->delete_slugs = (string)$data->delete_slugs ? explode(',',(string)$data->delete_slugs) : [];
$settings->create_lock = (bool) (string) $data->create_lock;
$settings->special_pages_enabled = (bool) (string) $data->special_pages_enabled;
$settings->special_types = explode(',',(string)$data->special_types);
$settings->special_pages_security = (bool) (string) $data->special_pages_security;
return $settings;
}
//saves settings to xml
function page_lock_save_settings( $visibility_lock = 0,
$template_lock = 0,
$parent_lock = 0,
$slug_lock = 0,
$options_slugs = '',
$preview_lock = 0,
$special_browse_remove = 0,
$delete_lock = 0,
$delete_slugs = '',
$create_lock = 0,
$special_pages_enabled = 0,
$special_types = '' ,
$special_pages_security = 0
) {
$file = GSDATAOTHERPATH . 'pagelock.xml';
$xml = new SimpleXMLExtended('<?xml version="1.0" encoding="UTF-8"?><settings></settings>');
$xml->addChild('visibility_lock', $visibility_lock);
$xml->addChild('template_lock', $template_lock);
$xml->addChild('parent_lock', $parent_lock);
$xml->addChild('slug_lock', $slug_lock);
$xml->addChild('preview_lock', $preview_lock);
$xml->addChild('special_browse_remove', $special_browse_remove);
$xml->addChild('delete_lock', $delete_lock);
$obj = $xml->addChild('options_slugs');
$obj->addCData($options_slugs);
$obj = $xml->addChild('delete_slugs');
$obj->addCData($delete_slugs);
$xml->addChild('create_lock', $create_lock);
$xml->addChild('special_pages_enabled', $special_pages_enabled);
$obj = $xml->addChild('special_types');
$obj->addCData($special_types);
$xml->addChild('special_pages_security', $special_pages_security);
# write data to file
return XMLsave($xml, $file) === true ? true : false;
}