forked from zikula/core
/
Admin.php
1400 lines (1154 loc) · 59.9 KB
/
Admin.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
/**
* Copyright Zikula Foundation 2009 - Zikula Application Framework
*
* This work is contributed to the Zikula Foundation under one or more
* Contributor Agreements and licensed to You under the following license:
*
* @license GNU/LGPLv3 (or at your option, any later version).
* @package Zikula
*
* Please see the NOTICE file distributed with this source code for further
* information regarding copyright and licensing.
*/
class Theme_Controller_Admin extends Zikula_AbstractController
{
/**
* Post initialise.
*
* @return void
*/
protected function postInitialize()
{
// In this controller we do not want caching.
$this->view->setCaching(Zikula_View::CACHE_DISABLED);
}
/**
* the main admin function
*/
public function main()
{
// Security check will be done in view()
$this->redirect(ModUtil::url('Theme', 'admin', 'view'));
}
/**
* view all themes
*/
public function view($args = array())
{
// Security check
if (!SecurityUtil::checkPermission('Theme::', '::', ACCESS_EDIT)) {
return LogUtil::registerPermissionError();
}
if (isset($this->serviceManager['multisites.enabled']) && $this->serviceManager['multisites.enabled'] == 1) {
// only the main site can regenerate the themes list
if ($this->serviceManager['multisites.mainsiteurl'] == FormUtil::getPassedValue('sitedns', null, 'GET')) {
//return true but any action has been made
ModUtil::apiFunc('Theme', 'admin', 'regenerate');
}
} else {
ModUtil::apiFunc('Theme', 'admin', 'regenerate');
}
// get our input
$startnum = FormUtil::getPassedValue('startnum', isset($args['startnum']) ? $args['startnum'] : 1, 'GET');
$startlet = FormUtil::getPassedValue('startlet', isset($args['startlet']) ? $args['startlet'] : null, 'GET');
// we need this value multiple times, so we keep it
$itemsperpage = $this->getVar('itemsperpage');
// call the API to get a list of all themes in the themes dir
$allthemes = ThemeUtil::getAllThemes(ThemeUtil::FILTER_ALL, ThemeUtil::STATE_ALL);
// filter by letter if required
if (isset($startlet) && !empty($startlet)) {
$allthemes = $this->_filterbyletter($allthemes, $startlet);
}
$themes = array_slice($allthemes, $startnum-1, $itemsperpage);
$this->view->assign('themes', $themes);
// assign default theme
$this->view->assign('currenttheme', System::getVar('Default_Theme'));
// assign the values for the pager plugin
$this->view->assign('pager', array('numitems' => sizeof($allthemes),
'itemsperpage' => $itemsperpage));
// return the output that has been generated to the template
return $this->view->fetch('theme_admin_view.tpl');
}
/**
* filter theme array by letter
*
* @access private
*/
private function _filterbyletter($allthemes, $startlet)
{
$themes = array();
$startlet = strtolower($startlet);
foreach ($allthemes as $key => $theme) {
if (strtolower($key[0]) == $startlet) {
$themes[$key] = $theme;
}
}
return $themes;
}
/**
* Running config checker
*/
private function checkRunningConfig($themeinfo)
{
$ostemp = CacheUtil::getLocalDir();
$zpath = $ostemp.'/Theme_Config/'.DataUtil::formatForOS($themeinfo['directory']);
$tpath = 'themes/'.DataUtil::formatForOS($themeinfo['directory']).'/templates/config';
// check if we can edit the theme and, if not, create the running config
if (!is_writable($tpath.'/pageconfigurations.ini')) {
if (!file_exists($zpath) || is_writable($zpath)) {
ModUtil::apiFunc('Theme', 'admin', 'createrunningconfig', array('themename' => $themeinfo['name']));
LogUtil::registerStatus($this->__f('Notice: The changes made via Admin Panel will be saved on \'%1$s\' because it seems that the .ini files on \'%2$s\' are not writable.', array($zpath, $tpath)));
} else {
LogUtil::registerError($this->__f('Error! Cannot write any configuration changes. Make sure that the .ini files on \'%1$s\' or \'%2$s\', and the folder itself, are writable.', array($tpath, $zpath)));
}
} else {
LogUtil::registerStatus($this->__f('Notice: Seems that your %1$s\'s .ini files are writable. Be sure that there are no .ini files on \'%2$s\' because if so, the Theme Engine will consider them and not your %1$s\'s ones.', array($themeinfo['name'], $zpath)));
}
LogUtil::registerStatus($this->__f("If the system cannot write on any .ini file, the changes will be saved on '%s' and the Theme Engine will use it.", $zpath));
}
/**
* modify theme
*/
public function modify($args)
{
// get our input
$themename = FormUtil::getPassedValue('themename', isset($args['themename']) ? $args['themename'] : null, 'GET');
// check our input
if (!isset($themename) || empty($themename)) {
return LogUtil::registerArgsError(ModUtil::url('Theme', 'admin', 'view'));
}
// Security check
if (!SecurityUtil::checkPermission('Theme::', "$themename::", ACCESS_EDIT)) {
return LogUtil::registerPermissionError();
}
// get the theme info
$themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName($themename));
// check that we have writable files
$this->checkRunningConfig($themeinfo);
// assign theme name, theme info and return output
return $this->view->assign('themename', $themename)
->assign('themeinfo', $themeinfo)
->fetch('theme_admin_modify.tpl');
}
/**
* update the theme variables
*
*/
public function updatesettings($args)
{
$this->checkCsrfToken();
// get our input
$themeinfo = FormUtil::getPassedValue('themeinfo', isset($args['themeinfo']) ? $args['themeinfo'] : null, 'POST');
$themename = FormUtil::getPassedValue('themename', isset($args['themename']) ? $args['themename'] : null, 'POST');
// check our input
if (!isset($themename) || empty($themename)) {
LogUtil::registerArgsError();
$this->redirect(ModUtil::url('Theme', 'admin', 'view'));
}
// Security check
if (!SecurityUtil::checkPermission('Theme::', "$themename::settings", ACCESS_EDIT)) {
return LogUtil::registerPermissionError();
}
// get the existing theme info
$curthemeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName($themename));
// reset the flag fields so that the form settings always get used
$curthemeinfo['user'] = 0;
$curthemeinfo['system'] = 0;
$curthemeinfo['admin'] = 0;
// add the new theme variable to the existing variables
$newthemeinfo = array_merge($curthemeinfo, $themeinfo);
// rewrite the variables to the running config
if (ModUtil::apiFunc('Theme', 'admin', 'updatesettings', array('theme' => $themename, 'themeinfo' => $newthemeinfo))) {
LogUtil::registerStatus($this->__('Done! Saved module configuration.'));
}
// redirect back to the variables page
$this->redirect(ModUtil::url('Theme', 'admin', 'view'));
}
/**
* display the theme variables
*
*/
public function variables($args)
{
// get our input
$themename = FormUtil::getPassedValue('themename', isset($args['themename']) ? $args['themename'] : null, 'GET');
$filename = FormUtil::getPassedValue('filename', isset($args['filename']) ? $args['filename'] : null, 'GET');
// check our input
if (empty($themename)) {
return LogUtil::registerArgsError(ModUtil::url('Theme', 'admin', 'view'));
}
$themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName($themename));
if (!file_exists('themes/'.DataUtil::formatForOS($themeinfo['directory']).'/version.php')) {
return LogUtil::registerArgsError(ModUtil::url('Theme', 'admin', 'view'));
}
// Security check
if (!SecurityUtil::checkPermission('Theme::', "$themename::variables", ACCESS_EDIT)) {
return LogUtil::registerPermissionError();
}
if ($filename) {
$variables = ModUtil::apiFunc('Theme', 'user', 'getpageconfiguration', array('theme' => $themename, 'filename' => $filename));
$variables = ModUtil::apiFunc('Theme', 'user', 'formatvariables', array('theme' => $themename, 'variables' => $variables, 'formatting' => true));
} else {
$variables = ModUtil::apiFunc('Theme', 'user', 'getvariables', array('theme' => $themename, 'formatting' => true));
}
// load the language file
ZLanguage::bindThemeDomain($themename);
// check that we have writable files
$this->checkRunningConfig($themeinfo);
// assign variables, themename, themeinfo and return output
return $this->view->assign('variables', $variables)
->assign('themename', $themename)
->assign('themeinfo', $themeinfo)
->assign('filename', $filename)
->fetch('theme_admin_variables.tpl');
}
/**
* update the theme variables
*
*/
public function updatevariables($args)
{
$this->checkCsrfToken();
// get our input
$variablesnames = FormUtil::getPassedValue('variablesnames', isset($args['variablesnames']) ? $args['variablesnames'] : null, 'POST');
$variablesvalues = FormUtil::getPassedValue('variablesvalues', isset($args['variablesvalues']) ? $args['variablesvalues'] : null, 'POST');
$newvariablename = FormUtil::getPassedValue('newvariablename', isset($args['newvariablename']) ? $args['newvariablename'] : null, 'POST');
$newvariablevalue = FormUtil::getPassedValue('newvariablevalue', isset($args['newvariablevalue']) ? $args['newvariablevalue'] : null, 'POST');
$themename = FormUtil::getPassedValue('themename', isset($args['themename']) ? $args['themename'] : null, 'POST');
$filename = FormUtil::getPassedValue('filename', isset($args['filename']) ? $args['filename'] : null, 'POST');
// check our input
if (!isset($themename) || empty($themename)) {
return LogUtil::registerArgsError(ModUtil::url('Theme', 'admin', 'view'));
}
$themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName($themename));
if (!file_exists('themes/'.DataUtil::formatForOS($themeinfo['directory']).'/version.php')) {
return LogUtil::registerArgsError(ModUtil::url('Theme', 'admin', 'view'));
}
// Security check
if (!SecurityUtil::checkPermission('Theme::', "$themename::variables", ACCESS_EDIT)) {
return LogUtil::registerPermissionError();
}
// get the original file source
if ($filename) {
$variables = ModUtil::apiFunc('Theme', 'user', 'getpageconfiguration', array('theme' => $themename, 'filename' => $filename));
$returnurl = ModUtil::url('Theme', 'admin', 'variables', array('themename' => $themename, 'filename' => $filename));
} else {
$filename = 'themevariables.ini';
$variables = ModUtil::apiFunc('Theme', 'user', 'getvariables', array('theme' => $themename));
$returnurl = ModUtil::url('Theme', 'admin', 'variables', array('themename' => $themename));
}
// form our existing variables
$newvariables = array();
foreach ($variablesnames as $id => $variablename) {
preg_match('/^([\d\w_)]+)(\[([\d\w_)]+)\])?$/', $variablename, $matches);
if (isset($matches[1])) {
if (isset($matches[3])) {
$newvariables[$matches[1]][$matches[3]] = $variablesvalues[$id];
} else {
$newvariables[$matches[1]] = $variablesvalues[$id];
}
}
}
// add the new theme variable to the existing variables
if (!empty($newvariablename) && !empty($newvariablevalue)) {
preg_match('/^([\d\w_)]+)(\[([\d\w_)]+)\])?$/', $newvariablename, $matches);
if (isset($matches[1])) {
if (isset($matches[3])) {
$newvariables[$matches[1]][$matches[3]] = $newvariablevalue;
} else {
$newvariables[$matches[1]] = $newvariablevalue;
}
}
}
// re-add the new values
$variables['variables'] = $newvariables;
// rewrite the variables to the running config
ModUtil::apiFunc('Theme', 'user', 'writeinifile', array('theme' => $themename, 'assoc_arr' => $variables, 'has_sections' => true, 'file' => $filename));
// set a status message
LogUtil::registerStatus($this->__('Done! Saved your changes.'));
// redirect back to the variables page
$this->redirect($returnurl);
}
/**
* display the themes palettes
*
*/
public function palettes($args)
{
// get our input
$themename = FormUtil::getPassedValue('themename', isset($args['themename']) ? $args['themename'] : null, 'GET');
// check our input
if (!isset($themename) || empty($themename)) {
return LogUtil::registerArgsError(ModUtil::url('Theme', 'admin', 'view'));
}
$themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName($themename));
if (!file_exists('themes/'.DataUtil::formatForOS($themeinfo['directory']).'/version.php')) {
return LogUtil::registerArgsError(ModUtil::url('Theme', 'admin', 'view'));
}
// Security check
if (!SecurityUtil::checkPermission('Theme::', "$themename::colors", ACCESS_EDIT)) {
return LogUtil::registerPermissionError();
}
// check that we have writable files
$this->checkRunningConfig($themeinfo);
// assign palettes, themename, themeinfo and return output
return $this->view->assign('palettes', ModUtil::apiFunc('Theme', 'user', 'getpalettes', array('theme' => $themename)))
->assign('themename', $themename)
->assign('themeinfo', $themeinfo)
->fetch('theme_admin_palettes.tpl');
}
/**
* update the theme palettes
*
*/
public function updatepalettes($args)
{
$this->checkCsrfToken();
// get our input
$palettes = FormUtil::getPassedValue('palettes', isset($args['palettes']) ? $args['palettes'] : null, 'POST');
$palettename = FormUtil::getPassedValue('palettename', isset($args['palettename']) ? $args['palettename'] : null, 'POST');
$bgcolor = FormUtil::getPassedValue('bgcolor', isset($args['bgcolor']) ? $args['bgcolor'] : null, 'POST');
$color1 = FormUtil::getPassedValue('color1', isset($args['color1']) ? $args['color1'] : null, 'POST');
$color2 = FormUtil::getPassedValue('color2', isset($args['color2']) ? $args['color2'] : null, 'POST');
$color3 = FormUtil::getPassedValue('color3', isset($args['color3']) ? $args['color3'] : null, 'POST');
$color4 = FormUtil::getPassedValue('color4', isset($args['color4']) ? $args['color4'] : null, 'POST');
$color5 = FormUtil::getPassedValue('color5', isset($args['color5']) ? $args['color5'] : null, 'POST');
$color6 = FormUtil::getPassedValue('color6', isset($args['color6']) ? $args['color6'] : null, 'POST');
$color7 = FormUtil::getPassedValue('color7', isset($args['color7']) ? $args['color7'] : null, 'POST');
$color8 = FormUtil::getPassedValue('color8', isset($args['color8']) ? $args['color8'] : null, 'POST');
$sepcolor = FormUtil::getPassedValue('sepcolor', isset($args['sepcolor']) ? $args['sepcolor'] : null, 'POST');
$link = FormUtil::getPassedValue('link', isset($args['link']) ? $args['link'] : null, 'POST');
$vlink = FormUtil::getPassedValue('vlink', isset($args['vlink']) ? $args['vlink'] : null, 'POST');
$hover = FormUtil::getPassedValue('hover', isset($args['hover']) ? $args['hover'] : null, 'POST');
$themename = FormUtil::getPassedValue('themename', isset($args['themename']) ? $args['themename'] : null, 'POST');
// check if this is a valid theme
$themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName($themename));
if (!file_exists('themes/'.DataUtil::formatForOS($themeinfo['directory']).'/version.php')) {
return LogUtil::registerArgsError(ModUtil::url('Theme', 'admin', 'view'));
}
// Security check
if (!SecurityUtil::checkPermission('Theme::', "$themename::palettes", ACCESS_EDIT)) {
return LogUtil::registerPermissionError();
}
// check if we've got a new palette being created
if (isset($themename) && !empty($themename) &&
isset($palettename) && !empty($palettename) &&
isset($bgcolor) && !empty($bgcolor) &&
isset($color1) && !empty($color1) &&
isset($color2) && !empty($color2) &&
isset($color3) && !empty($color3) &&
isset($color4) && !empty($color4) &&
isset($color5) && !empty($color5) &&
isset($color6) && !empty($color6) &&
isset($color7) && !empty($color7) &&
isset($color8) && !empty($color8) &&
isset($sepcolor) && !empty($sepcolor) &&
isset($link) && !empty($link) &&
isset($vlink) && !empty($vlink) &&
isset($hover) && !empty($hover)) {
// add the new theme setting to the existing settings
$palettes[$palettename] = array('bgcolor' => $bgcolor, 'color1' => $color1, 'color2' => $color2, 'color3' => $color3,
'color4' => $color4, 'color5' => $color5, 'color6' => $color6, 'color7' => $color7, 'color8' => $color8,
'sepcolor' => $sepcolor, 'link' => $link, 'vlink' => $vlink, 'hover' => $hover) ;
} else {
LogUtil::registerError($this->__('Notice: Please make sure you type an entry in every field. Your palette cannot be saved if you do not.'));
return System::redirect(ModUtil::url('Theme', 'admin', 'view'));
}
// rewrite the settings to the running config
ModUtil::apiFunc('Theme', 'user', 'writeinifile', array('theme' => $themename, 'assoc_arr' => $palettes, 'has_sections' => true, 'file' => 'themepalettes.ini'));
// set a status message
LogUtil::registerStatus($this->__('Done! Saved your changes.'));
// redirect back to the settings page
$this->redirect(ModUtil::url('Theme', 'admin', 'palettes', array('themename' => $themename)));
}
/**
* display the content wrappers for the theme
*
*/
public function pageconfigurations($args)
{
// get our input
$themename = FormUtil::getPassedValue('themename', isset($args['themename']) ? $args['themename'] : null, 'GET');
// check our input
if (!isset($themename) || empty($themename)) {
return LogUtil::registerArgsError(ModUtil::url('Theme', 'admin', 'view'));
}
$themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName($themename));
if (!file_exists('themes/'.DataUtil::formatForOS($themeinfo['directory']).'/version.php')) {
return LogUtil::registerArgsError(ModUtil::url('Theme', 'admin', 'view'));
}
// Security check
if (!SecurityUtil::checkPermission('Theme::', "$themename::pageconfigurations", ACCESS_EDIT)) {
return LogUtil::registerPermissionError();
}
// assign an array to populate the modules dropdown
$allmods = ModUtil::getAllMods();
$mods = array();
foreach ($allmods as $mod) {
$mods[$mod['name']] = $mod['displayname'];
}
// assign the page configuration assignments
$pageconfigurations = ModUtil::apiFunc('Theme', 'user', 'getpageconfigurations', array('theme' => $themename));
// defines the default types and master
$pagetypes = array(
'master' => $this->__('Master'),
'*home' => $this->__('Homepage'),
'*admin' => $this->__('Admin panel pages'),
'*editor' => $this->__('Editor panel pages')
);
// checks the page configuration files in use
$pageconfigfiles = array();
foreach ($pageconfigurations as $name => $pageconfiguration) {
// checks for non-standard pagetypes
if (strpos($name, '*') === 0 && !isset($pagetypes[$name])) {
//! Pages inside a specific Controller type (editor, moderator, user)
$pagetypes[$name] = $this->__f('%s type pages', ucfirst(substr($name, 1)));
}
// check if the file exists
if ($exists = file_exists("themes/$themeinfo[directory]/templates/config/$pageconfiguration[file]")) {
$existingconfigs[] = $pageconfiguration['file'];
}
$pageconfigfiles[$pageconfiguration['file']] = $exists;
}
ksort($pageconfigfiles);
// gets the available page configurations on the theme
$existingconfigs = ModUtil::apiFunc('Theme', 'user', 'getconfigurations', array('theme' => $themename));
// check that we have writable files
$this->checkRunningConfig($themeinfo);
// assign the output vars
$this->view->assign('themename', $themename)
->assign('themeinfo', $themeinfo)
->assign('pagetypes', $pagetypes)
->assign('modules', $mods)
->assign('pageconfigurations', $pageconfigurations)
->assign('pageconfigs', $pageconfigfiles)
->assign('existingconfigs', $existingconfigs);
// Return the output that has been generated by this function
return $this->view->fetch('theme_admin_pageconfigurations.tpl');
}
/**
* modify a theme page configuration
*
*/
public function modifypageconfigtemplates($args)
{
// get our input
$themename = FormUtil::getPassedValue('themename', isset($args['themename']) ? $args['themename'] : null, 'GET');
$filename = FormUtil::getPassedValue('filename', isset($args['filename']) ? $args['filename'] : null, 'GET');
// check our input
if (empty($themename)) {
return LogUtil::registerArgsError(ModUtil::url('Theme', 'admin', 'view'));
}
$themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName($themename));
if (!file_exists('themes/'.DataUtil::formatForOS($themeinfo['directory']).'/version.php')) {
return LogUtil::registerArgsError(ModUtil::url('Theme', 'admin', 'view'));
}
// Security check
if (!SecurityUtil::checkPermission('Theme::', "$themename::pageconfigurations", ACCESS_EDIT)) {
return LogUtil::registerPermissionError();
}
// read our configuration file
$pageconfiguration = ModUtil::apiFunc('Theme', 'user', 'getpageconfiguration', array('theme' => $themename, 'filename' => $filename));
if (empty($pageconfiguration)) {
return LogUtil::registerArgsError(ModUtil::url('Theme', 'admin', 'view'));
}
// get all block positions
$blockpositions = ModUtil::apiFunc('Blocks', 'user', 'getallpositions');
foreach ($blockpositions as $name => $blockposition) {
// check the page configuration
if (!isset($pageconfiguration['blockpositions'][$blockposition['name']])) {
$pageconfiguration['blockpositions'][$name] = '';
}
$blockpositions[$name] = $blockposition['description'];
}
// call the block API to get a list of all available blocks
$allblocks = BlockUtil::loadAll();
foreach ($allblocks as $key => $blocks) {
foreach ($blocks as $k => $block) {
$allblocks[$key][$k]['bkey'] = $bkey = strtolower($block['bkey']);
// check the page configuration
if (!isset($pageconfiguration['blocktypes'][$bkey])) {
$pageconfiguration['blocktypes'][$bkey] = '';
}
}
}
// call the block API to get a list of all defined block instances
$blocks = ModUtil::apiFunc('Blocks', 'user', 'getall');
foreach ($blocks as $block) {
// check the page configuration
if (!isset($pageconfiguration['blockinstances'][$block['bid']])) {
$pageconfiguration['blockinstances'][$block['bid']] = '';
}
}
// palette default
if (!isset($pageconfiguration['palette'])) {
$pageconfiguration['palette'] = '';
}
// block default
if (!isset($pageconfiguration['block'])) {
$pageconfiguration['block'] = '';
}
// filters defaults
if (!isset($pageconfiguration['filters']['outputfilters'])) {
$pageconfiguration['filters']['outputfilters'] = '';
}
if (!isset($pageconfiguration['filters']['prefilters'])) {
$pageconfiguration['filters']['prefilters'] = '';
}
if (!isset($pageconfiguration['filters']['postfilters'])) {
$pageconfiguration['filters']['postfilters'] = '';
}
$this->view->setCaching(Zikula_View::CACHE_DISABLED);
// assign the output variables and fetch the template
return $this->view->assign('filename', $filename)
->assign('themename', $themename)
->assign('themeinfo', $themeinfo)
->assign('moduletemplates', ModUtil::apiFunc('Theme', 'user', 'gettemplates', array('theme' => $themename)))
->assign('blocktemplates', ModUtil::apiFunc('Theme', 'user', 'gettemplates', array('theme' => $themename, 'type' => 'blocks')))
->assign('palettes', ModUtil::apiFunc('Theme', 'user', 'getpalettenames', array('theme' => $themename)))
->assign('blockpositions', $blockpositions)
->assign('allblocks', $allblocks)
->assign('blocks', $blocks)
->assign('pageconfiguration', $pageconfiguration)
->fetch('theme_admin_modifypageconfigtemplates.tpl');
}
/**
* modify a theme page configuration
*
*/
public function updatepageconfigtemplates($args)
{
$this->checkCsrfToken();
// get our input
$themename = FormUtil::getPassedValue('themename', isset($args['themename']) ? $args['themename'] : null, 'POST');
$filename = FormUtil::getPassedValue('filename', isset($args['filename']) ? $args['filename'] : null, 'POST');
$pagetemplate = FormUtil::getPassedValue('pagetemplate', isset($args['pagetemplate']) ? $args['pagetemplate'] : '', 'POST');
$blocktemplate = FormUtil::getPassedValue('blocktemplate', isset($args['blocktemplate']) ? $args['blocktemplate'] : '', 'POST');
$pagepalette = FormUtil::getPassedValue('pagepalette', isset($args['pagepalette']) ? $args['pagepalette'] : '', 'POST');
$modulewrapper = FormUtil::getPassedValue('modulewrapper', isset($args['modulewrapper']) ? $args['modulewrapper'] : 1, 'POST');
$blockwrapper = FormUtil::getPassedValue('blockwrapper', isset($args['blockwrapper']) ? $args['blockwrapper'] : 1, 'POST');
$blockinstancetemplates = FormUtil::getPassedValue('blockinstancetemplates', isset($args['blockinstancetemplates']) ? $args['blockinstancetemplates'] : null, 'POST');
$blocktypetemplates = FormUtil::getPassedValue('blocktypetemplates', isset($args['blocktypetemplates']) ? $args['blocktypetemplates'] : null, 'POST');
$blockpositiontemplates = FormUtil::getPassedValue('blockpositiontemplates', isset($args['blockpositiontemplates']) ? $args['blockpositiontemplates'] : null, 'POST');
$filters = FormUtil::getPassedValue('filters', isset($args['filters']) ? $args['filters'] : null, 'POST');
// check our input
if (empty($themename) || empty($pagetemplate)) {
return LogUtil::registerArgsError(ModUtil::url('Theme', 'admin', 'view'));
}
$themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName($themename));
if (!file_exists('themes/'.DataUtil::formatForOS($themeinfo['directory']).'/version.php')) {
return LogUtil::registerArgsError(ModUtil::url('Theme', 'admin', 'view'));
}
// Security check
if (!SecurityUtil::checkPermission('Theme::', "$themename::pageconfigurations", ACCESS_EDIT)) {
return LogUtil::registerPermissionError();
}
// read our configuration file
$pageconfiguration = ModUtil::apiFunc('Theme', 'user', 'getpageconfiguration', array('theme' => $themename, 'filename' => $filename));
if (empty($pageconfiguration)) {
return LogUtil::registerArgsError(ModUtil::url('Theme', 'admin', 'view'));
}
// form the new page configuration
$pageconfiguration['page'] = $pagetemplate;
$pageconfiguration['block'] = $blocktemplate;
$pageconfiguration['palette'] = $pagepalette;
$pageconfiguration['modulewrapper'] = $modulewrapper;
$pageconfiguration['blockwrapper'] = $blockwrapper;
$pageconfiguration['blockinstances'] = array_filter($blockinstancetemplates);
$pageconfiguration['blocktypes'] = array_filter($blocktypetemplates);
$pageconfiguration['blockpositions'] = array_filter($blockpositiontemplates);
// check if the filters exists. We do this now and not when using them to increase performance
$filters['outputfilters'] = $this->_checkfilters('outputfilter', $filters['outputfilters']);
$filters['prefilters'] = $this->_checkfilters('prefilter', $filters['prefilters']);
$filters['postfilters'] = $this->_checkfilters('postfilter', $filters['postfilters']);
$pageconfiguration['filters'] = $filters;
// write the page configuration
ModUtil::apiFunc('Theme', 'user', 'writeinifile', array('theme' => $themename, 'assoc_arr' => $pageconfiguration, 'has_sections' => true, 'file' => $filename));
// set a status message
LogUtil::registerStatus($this->__('Done! Saved your changes.'));
// return the user to the correct place
$this->redirect(ModUtil::url('Theme', 'admin', 'pageconfigurations', array('themename' => $themename)));
}
/**
* Check if the given filter exists
*
*/
private function _checkfilters($type, $filters)
{
$filters = trim($filters);
if (empty($filters)) {
return $filters;
}
$ostype = DataUtil::formatForOS($type);
$filters = explode(',', $filters);
$newfilters = array();
foreach ($filters as $filter) {
foreach ($this->view->plugins_dir as $plugindir) {
if (file_exists($plugindir .'/'. $ostype .'.'. DataUtil::formatForOS($filter) .'.php')) {
$newfilters[] = $filter;
break;
}
}
}
$leftover = array_diff($filters, $newfilters);
if (count($leftover) > 0) {
LogUtil::registerError($this->__f('Error! Removed unknown \'%1$s\': \'%2$s\'.', array(DataUtil::formatForDisplay($type), DataUtil::formatForDisplay(implode(',', $leftover)))));
}
return implode(',', $newfilters);
}
/**
* Modify a theme page configuration
*
*/
public function modifypageconfigurationassignment($args)
{
// get our input
$themename = FormUtil::getPassedValue('themename', isset($args['themename']) ? $args['themename'] : null, 'GET');
$pcname = FormUtil::getPassedValue('pcname', isset($args['pcname']) ? $args['pcname'] : null, 'GET');
// check our input
if (!isset($themename) || empty($themename)) {
return LogUtil::registerArgsError(ModUtil::url('Theme', 'admin', 'view'));
}
$themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName($themename));
if (!file_exists('themes/'.DataUtil::formatForOS($themeinfo['directory']).'/version.php')) {
return LogUtil::registerArgsError(ModUtil::url('Theme', 'admin', 'view'));
}
// Security check
if (!SecurityUtil::checkPermission('Theme::', "$themename::pageconfigurations", ACCESS_EDIT)) {
return LogUtil::registerPermissionError();
}
// assign all modules
$allmods = ModUtil::getAllMods();
$mods = array();
foreach ($allmods as $mod) {
$mods[$mod['name']] = $mod['name'];
}
// get all pageconfigurations
$pageconfigurations = ModUtil::apiFunc('Theme', 'user', 'getpageconfigurations', array('theme' => $themename));
if (!isset($pageconfigurations[$pcname])) {
LogUtil::registerError($this->__('Error! No such page configuration assignment found.'));
$this->redirect(ModUtil::url('Theme', 'admin', 'view'));
}
// defines the default types and master
$pagetypes = array(
'master' => $this->__('Master'),
'*home' => $this->__('Homepage'),
'*admin' => $this->__('Admin panel pages'),
'*editor' => $this->__('Editor panel pages')
);
// checks for non-standard pagetypes
foreach ($pageconfigurations as $name => $pageconfiguration) {
if (strpos($name, '*') === 0 && !isset($pagetypes[$name])) {
//! Pages inside a specific Controller type (editor, moderator, user)
$pagetypes[$name] = $this->__f('%s type pages', ucfirst(substr($name, 1)));
}
}
// form the page config assignment array setting some useful key names
$pageconfigassignment = array('pagemodule' => null, 'pagetype' => null, 'pagefunc' => null, 'pagecustomargs' => null);
$pageconfigparts = explode('/', $pcname);
$pageconfigassignment['pagemodule'] = $pageconfigparts[0];
if (isset($pageconfigparts[1])) {
$pageconfigassignment['pagetype'] = $pageconfigparts[1];
}
if (isset($pageconfigparts[2])) {
$pageconfigassignment['pagefunc'] = $pageconfigparts[2];
}
if (isset($pageconfigparts[3])) {
$pageconfigassignment['pagecustomargs'] = $pageconfigparts[3];
}
if (isset($pageconfigurations[$pcname]['important']) && $pageconfigurations[$pcname]['important']) {
$pageconfigassignment['important'] = 1;
}
// gets the available page configurations on the theme
$existingconfigs = ModUtil::apiFunc('Theme', 'user', 'getconfigurations', array('theme' => $themename));
// assign the page config assignment name, theme name and theme info
$this->view->assign($pageconfigassignment)
->assign('existingconfigs', $existingconfigs)
->assign('pcname', $pcname)
->assign('themename', $themename)
->assign('themeinfo', $themeinfo)
->assign('pagetypes', $pagetypes)
->assign('modules', $mods)
->assign('filename', $pageconfigurations[$pcname]['file']);
// Return the output that has been generated by this function
return $this->view->fetch('theme_admin_modifypageconfigurationassignment.tpl');
}
/**
* modify a theme page configuration
*
*/
public function updatepageconfigurationassignment($args)
{
$this->checkCsrfToken();
// get our input
$themename = FormUtil::getPassedValue('themename', isset($args['themename']) ? $args['themename'] : null, 'POST');
$pcname = FormUtil::getPassedValue('pcname', isset($args['pcname']) ? $args['pcname'] : null, 'POST');
$pagemodule = FormUtil::getPassedValue('pagemodule', isset($args['pagemodule']) ? $args['pagemodule'] : null, 'POST');
$pagetype = FormUtil::getPassedValue('pagetype', isset($args['pagetype']) ? $args['pagetype'] : 'user', 'POST');
$pagefunc = FormUtil::getPassedValue('pagefunc', isset($args['pagefunc']) ? $args['pagefunc'] : null, 'POST');
$pagecustomargs = FormUtil::getPassedValue('pagecustomargs', isset($args['pagecustomargs']) ? $args['pagecustomargs'] : null, 'POST');
$pageimportant = FormUtil::getPassedValue('pageimportant', isset($args['pageimportant']) ? $args['pageimportant'] : null, 'POST');
$filename = FormUtil::getPassedValue('filename', isset($args['filename']) ? $args['filename'] : null, 'POST');
// check our input
if (!isset($themename) || empty($themename)) {
return LogUtil::registerArgsError(ModUtil::url('Theme', 'admin', 'view'));
}
$themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName($themename));
if (!file_exists('themes/'.DataUtil::formatForOS($themeinfo['directory']).'/version.php')) {
return LogUtil::registerArgsError(ModUtil::url('Theme', 'admin', 'view'));
}
// Security check
if (!SecurityUtil::checkPermission('Theme::', "$themename::pageconfigurations", ACCESS_EDIT)) {
return LogUtil::registerPermissionError();
}
// read the list of existing page config assignments
$pageconfigurations = ModUtil::apiFunc('Theme', 'user', 'getpageconfigurations', array('theme' => $themename));
// form the new page configuration
$newpageconfiguration = $pagemodule;
if (strpos($pagemodule, '*') !== 0 && $pagemodule != 'master') {
$newpageconfiguration .= '/';
if (isset($pagetype)) {
$newpageconfiguration .= $pagetype;
}
$newpageconfiguration .= '/';
if (isset($pagefunc)) {
$newpageconfiguration .= $pagefunc;
}
$newpageconfiguration .= '/';
if (isset($pagecustomargs)) {
$newpageconfiguration .= $pagecustomargs;
}
}
// remove any 'empty' parameters from the string
$newpageconfiguration = trim($newpageconfiguration, '/');
// remove the config assignment if was changed
if (isset($pcname) && isset($pageconfigurations[$pcname]) && $pcname != $newpageconfiguration) {
// need to place the new one in the old position
$keys = array_keys($pageconfigurations);
$pos = array_search($pcname, $keys);
$keys[$pos] = $newpageconfiguration;
$pageconfigurations = array_combine($keys, array_values($pageconfigurations));
}
// fill the pageconfiguration info
$pageconfigurations[$newpageconfiguration] = array('file' => $filename);
if (isset($pageimportant)) {
$pageconfigurations[$newpageconfiguration]['important'] = 1;
}
// write the page configurations back to the running config
ModUtil::apiFunc('Theme', 'user', 'writeinifile', array('theme' => $themename, 'assoc_arr' => $pageconfigurations, 'has_sections' => true, 'file' => 'pageconfigurations.ini'));
// set a status message
LogUtil::registerStatus($this->__('Done! Saved your changes.'));
// return the user to the correct place
$this->redirect(ModUtil::url('Theme', 'admin', 'pageconfigurations', array('themename' => $themename)));
}
/**
* delete a theme page configuration assignment
*
*/
public function deletepageconfigurationassignment($args)
{
$themename = FormUtil::getPassedValue('themename', isset($args['themename']) ? $args['themename'] : null, 'REQUEST');
$pcname = FormUtil::getPassedValue('pcname', isset($args['pcname']) ? $args['pcname'] : null, 'REQUEST');
$confirmation = FormUtil::getPassedValue('confirmation', null, 'POST');
// Get the theme info
$themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName($themename));
if ($themeinfo == false) {
return LogUtil::registerError($this->__('Sorry! No such item found.'));
}
// Security check
if (!SecurityUtil::checkPermission('Theme::', "$themename::pageconfigurations", ACCESS_DELETE)) {
return LogUtil::registerPermissionError();
}
// Check for confirmation.
if (empty($confirmation)) {
// No confirmation yet
// Assign the theme info
$this->view->assign($themeinfo);
// Assign the page configuration name
$this->view->assign('pcname', $pcname);
// Return the output that has been generated by this function
return $this->view->fetch('theme_admin_deletepageconfigurationassignment.tpl');
}
// If we get here it means that the user has confirmed the action
$this->checkCsrfToken();
// Delete the admin message
// The return value of the function is checked
if (ModUtil::apiFunc('Theme', 'admin', 'deletepageconfigurationassignment', array('themename' => $themename, 'pcname' => $pcname))) {
// Success
LogUtil::registerStatus($this->__('Done! Deleted it.'));
}
// return the user to the correct place
$this->redirect(ModUtil::url('Theme', 'admin', 'pageconfigurations', array('themename' => $themename)));
}
/**
* display the theme credits
*
*
*/
public function credits($args)
{
// get our input
$themename = FormUtil::getPassedValue('themename', isset($args['themename']) ? $args['themename'] : null, 'GET');
// check our input
if (!isset($themename) || empty($themename)) {
return LogUtil::registerArgsError(ModUtil::url('Theme', 'admin', 'view'));
}
// Security check
if (!SecurityUtil::checkPermission('Theme::', "$themename::credits", ACCESS_EDIT)) {
return LogUtil::registerArgsError(ModUtil::url('Theme', 'admin', 'view'));
}
// assign the theme info and return output
return $this->view->assign('themeinfo', ThemeUtil::getInfo(ThemeUtil::getIDFromName($themename)))
->fetch('theme_admin_credits.tpl');
}
/**
* set theme as default for site
*
*/
public function setasdefault($args)
{
// get our input
$themename = FormUtil::getPassedValue('themename', isset($args['themename']) ? $args['themename'] : null, 'REQUEST');
$confirmation = (int)FormUtil::getPassedValue ('confirmation', false, 'REQUEST');
$resetuserselected = FormUtil::getPassedValue('resetuserselected', isset($args['resetuserselected']) ? $args['resetuserselected'] : null, 'POST');
// check our input
if (!isset($themename) || empty($themename)) {
return LogUtil::registerArgsError(ModUtil::url('Theme', 'admin', 'view'));
}
// Security check
if (!SecurityUtil::checkPermission('Theme::', '::', ACCESS_ADMIN)) {
return LogUtil::registerPermissionError();
}
// Check for confirmation.
if (empty($confirmation)) {
// No confirmation yet
// Add a hidden field for the item ID to the output
$this->view->assign('themename', $themename);
// assign the var defining if users can change themes
$this->view->assign('theme_change', System::getVar('theme_change'));
// Return the output that has been generated by this function
return $this->view->fetch('theme_admin_setasdefault.tpl');
}
// If we get here it means that the user has confirmed the action
$this->checkCsrfToken();