@@ -87,7 +87,7 @@ private function loadThemeConfig() {
87
87
private function loadTemplateList ($ theme = null ) {
88
88
$ list = $ this ->themeConfig ['pages ' ] ?? [];
89
89
90
- $ pages = $ list + Cache::getInstance ()->cache (APP ,'template-list. ' . $ theme ,
90
+ $ pages = $ list + Cache::getInstance ()->cache (APP , 'template-list. ' . $ theme ,
91
91
function () use ($ theme ) {
92
92
return \Vvveb \getTemplateList ($ theme );
93
93
}, 604800 );
@@ -97,6 +97,10 @@ function () use ($theme) {
97
97
return $ pages ;
98
98
}
99
99
100
+ private function clearTemplateListCache ($ theme = null ) {
101
+ return Cache::getInstance ()->delete (APP , 'template-list. ' . $ theme );
102
+ }
103
+
100
104
private function loadEditorData () {
101
105
$ data = [];
102
106
@@ -328,7 +332,6 @@ function delete() {
328
332
$ post_id = $ this ->request ->post ['post_id ' ] ?? false ;
329
333
$ file = sanitizeFileName ($ this ->request ->post ['file ' ]);
330
334
$ themeFolder = $ this ->getThemeFolder ();
331
- //echo $themeFolder . DS . $file;
332
335
333
336
if ($ post_id ) {
334
337
$ type = 'page ' ;
@@ -375,7 +378,7 @@ function rename() {
375
378
}
376
379
377
380
$ currentFile = $ themeFolder . DS . $ file ;
378
- $ targetFile = $ themeFolder . DS . $ newfile;
381
+ $ targetFile = dirname ( $ currentFile ) . DS . basename ( $ newfile); //save in same folder
379
382
380
383
$ message = ['success ' => false , 'message ' => __ ('Error! ' )];
381
384
@@ -386,29 +389,75 @@ function rename() {
386
389
$ slug = slugify ($ name );
387
390
388
391
$ this ->posts = new PostSQL ();
389
- $ options = [
390
- 'post_id ' => $ post_id ,
391
- 'post_content ' => [
392
- 'name ' => $ name ,
393
- 'slug ' => $ slug ,
394
- ],
395
- ] + $ this ->global ;
392
+ $ data = $ this ->posts ->get (['post_id ' => $ post_id ]);
396
393
397
394
if ($ duplicate === 'true ' ) {
395
+ $ data = $ this ->posts ->get (['post_id ' => $ post_id ]);
396
+
397
+ if ($ data ) {
398
+ unset($ data ['post_id ' ]);
399
+ $ id = rand (1 , 1000 );
400
+
401
+ foreach ($ data ['post_content ' ] as &$ content ) {
402
+ unset($ content ['post_id ' ]);
403
+
404
+ if ($ content ['language_id ' ] == $ this ->global ['language_id ' ]) {
405
+ $ content ['name ' ] = $ name ;
406
+ $ content ['slug ' ] = $ slug ;
407
+ } else {
408
+ $ content ['name ' ] .= ' [ ' . __ ('duplicate ' ) . '] ' ;
409
+ $ content ['slug ' ] .= '- ' . __ ('duplicate ' ) . "- $ id " ;
410
+ }
411
+ }
412
+
413
+ if (isset ($ data ['post_to_taxonomy_item ' ])) {
414
+ foreach ($ data ['post_to_taxonomy_item ' ] as &$ item ) {
415
+ $ taxonomy_item [] = $ item ['taxonomy_item_id ' ];
416
+ }
417
+ }
418
+
419
+ if (isset ($ data ['post_to_site ' ])) {
420
+ foreach ($ data ['post_to_site ' ] as &$ item ) {
421
+ $ site_id [] = $ item ['site_id ' ];
422
+ }
423
+ }
424
+
425
+ $ startTemplateUrl = $ data ['template ' ] ?? "content/ $ type.html " ;
426
+ $ template = "content/ $ slug.html " ;
427
+
428
+ if (!@copy ($ themeFolder . DS . $ startTemplateUrl , $ themeFolder . DS . $ template )) {
429
+ $ template = $ data ['template ' ] ?? '' ;
430
+ }
431
+
432
+ $ result = $ this ->posts ->add ([
433
+ 'post ' => [
434
+ 'post_content ' => $ data ['post_content ' ],
435
+ 'taxonomy_item ' => $ taxonomy_item ?? [],
436
+ 'template ' => $ template ,
437
+ ] + $ data ,
438
+ 'site_id ' => $ site_id ,
439
+ ]);
440
+
441
+ if ($ result && isset ($ result ['post ' ])) {
442
+ $ message = ['success ' => true , 'url ' => url ('content/page/index ' , ['slug ' => $ slug ]), 'message ' => ucfirst ($ type ) . __ (' duplicated! ' )];
443
+ } else {
444
+ $ message = ['success ' => false , 'message ' => sprintf (__ ('Error duplicating %s! ' ), $ type )];
445
+ }
446
+ }
398
447
} else {
399
448
$ result = $ this ->posts ->editContent ($ options );
400
449
}
401
450
402
451
if ($ result && isset ($ result ['post_content ' ])) {
403
452
$ message = ['success ' => true , 'url ' => url ('content/page/index ' , ['slug ' => $ slug ]), 'message ' => ucfirst ($ type ) . __ (' renamed! ' )];
404
453
} else {
405
- $ message = ['success ' => false , 'message ' => sprintf (__ ('Error deleting %s! ' ), $ type )];
454
+ $ message = ['success ' => false , 'message ' => sprintf (__ ('Error renaming %s! ' ), $ type )];
406
455
}
407
456
}
408
457
} else {
409
458
if ($ duplicate === 'true ' ) {
410
- if (copy ($ currentFile , $ targetFile )) {
411
- $ message = ['success ' => true , 'newfile ' => $ newfile , 'message ' => __ ('File copied! ' )];
459
+ if (@ copy ($ currentFile , $ targetFile )) {
460
+ $ message = ['success ' => true , 'newfile ' => $ newfile , 'message ' => __ ('File copied! ' ), ' url ' => $ newfile ];
412
461
} else {
413
462
$ message = ['success ' => false , 'message ' => __ ('Error copying file! ' )];
414
463
}
@@ -421,6 +470,7 @@ function rename() {
421
470
}
422
471
}
423
472
473
+ $ this ->clearTemplateListCache (sanitizeFileName ($ this ->request ->get ['theme ' ] ?? false ));
424
474
$ this ->response ->setType ('json ' );
425
475
$ this ->response ->output ($ message );
426
476
}
@@ -520,13 +570,13 @@ function save() {
520
570
$ startTemplate = $ themeFolder . DS . $ startTemplateUrl ;
521
571
522
572
if (file_exists ($ startTemplate )) {
523
- if (! ($ html = @file_get_contents ($ startTemplate )) ) {
573
+ if (! ($ html = @file_get_contents ($ startTemplate ))) {
524
574
$ text .= sprintf (__ ('%s is not readable! ' ), $ startTemplate );
525
575
}
526
576
} else {
527
577
$ text .= sprintf (__ ('%s does not exist! ' ), $ startTemplate );
528
578
}
529
-
579
+
530
580
$ html = preg_replace ('@<base href[^>]+>@ ' , '<base href=" ' . $ baseUrl . '"> ' , $ html );
531
581
}
532
582
@@ -546,7 +596,16 @@ function save() {
546
596
}
547
597
}
548
598
549
- if (! $ startTemplateUrl ) {
599
+ //if plugins template use public path
600
+ $ isPlugin = false ;
601
+ if (substr_compare ($ file ,'/plugins/ ' , 0 , 9 ) === 0 ) {
602
+ $ fileName = DIR_PUBLIC . DS . ($ folder ? $ folder . DS : '' ) . $ file ;
603
+ $ isPlugin = true ;
604
+ } else {
605
+ $ fileName = $ themeFolder . DS . ($ folder ? $ folder . DS : '' ) . $ file ;
606
+ }
607
+
608
+ if (! $ startTemplateUrl && !$ isPlugin ) {
550
609
$ backupFolder = $ themeFolder . DS . 'backup ' . DS ;
551
610
552
611
if (is_writable ($ backupFolder )) {
@@ -581,13 +640,6 @@ function save() {
581
640
}
582
641
}
583
642
584
- //if plugins template use public path
585
- if (substr_compare ($ file [0 ],'/plugins/ ' , 0 , 9 ) === 0 ) {
586
- $ fileName = DIR_PUBLIC . DS . ($ folder ? $ folder . DS : '' ) . $ file ;
587
- } else {
588
- $ fileName = $ themeFolder . DS . ($ folder ? $ folder . DS : '' ) . $ file ;
589
- }
590
-
591
643
if ($ html ) {
592
644
if (@file_put_contents ($ fileName , $ html )) {
593
645
$ globalOptions = [];
0 commit comments