/
Theme.php
1002 lines (864 loc) · 31.1 KB
/
Theme.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_View
*
* Please see the NOTICE file distributed with this source code for further
* information regarding copyright and licensing.
*/
use Zikula\Core\Event\GenericEvent;
use Zikula\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Yaml\Yaml;
/**
* Zikula_View_Theme class.
*/
class Zikula_View_Theme extends Zikula_View
{
// base theme info
/**
* Theme name.
*
* @var string
*/
public $name;
/**
* Directory.
*
* @var string
*/
public $directory;
/**
* Version.
*
* @var string
*/
public $version;
/**
* State.
*
* @var integer
*/
public $state;
/**
* XHTML capable.
*
* @var integer
*/
public $xhtml;
// base theme properties
/**
* Theme base path.
*
* @var string
*/
public $themepath;
/**
* Theme image path.
*
* @var string
*/
public $imagepath;
/**
* Theme language image path.
*
* @var string
*/
public $imagelangpath;
/**
* Theme stylesheet path.
*
* @var string
*/
public $stylepath;
/**
* Theme script path.
*
* @var string
*/
public $scriptpath;
/**
* Theme config.
*
* @var array
*/
public $themeconfig;
// base user information
/**
* User id.
*
* @var integer
*/
public $uid;
/**
* Whether or not the user is logged in.
*
* @var boolean.
*/
public $isloggedin;
// publics to identify our page
/**
* Page type.
*
* @var string
*/
public $pagetype;
/**
* Query string.
*
* @var string
*/
public $qstring;
/**
* Request Uri.
*
* @var string
*/
public $requesturi;
/**
* Internal override Map.
*
* @var array
*/
protected $_overrideMap = array();
/**
* Constructor.
*
* @param ContainerBuilder $container ServiceManager.
* @param string $themeName Theme name.
*/
public function __construct(ContainerBuilder $container, $themeName)
{
// store our theme information
$this->themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName($themeName));
// prevents any case mismatch
$themeName = $this->themeinfo['name'];
foreach (array('name', 'directory', 'version', 'state', 'xhtml') as $key) {
$this->$key = $this->themeinfo[$key];
}
parent::__construct($container);
if ($this->themeinfo['i18n']) {
ZLanguage::bindThemeDomain($this->name);
// property for {gt} template plugin to detect language domain
$this->domain = ZLanguage::getThemeDomain($this->name);
} else {
$this->domain = null;
}
EventUtil::attachCustomHandlers("themes/$themeName/EventHandlers");
if (is_readable("themes/$themeName/Resources/config/overrides.yml")) {
$this->dispatcher->addListener('zikula_view.template_override', array($this, '_templateOverride'), 0);
$this->_overrideMap = Yaml::parse("themes/$themeName/Resources/config/overrides.yml");
}
$event = new GenericEvent($this);
$this->dispatcher->dispatch('theme.preinit', $event);
// change some base settings from our parent class
// template compilation
$this->compile_dir = CacheUtil::getLocalDir('Theme_compiled');
$this->compile_check = ModUtil::getVar('Theme', 'compile_check');
$this->force_compile = ModUtil::getVar('Theme', 'force_compile');
// template caching
$this->cache_dir = CacheUtil::getLocalDir('Theme_cache');
$this->caching = (int)ModUtil::getVar('Theme', 'enablecache');
//if ($this->caching) {
// $this->cache_modified_check = true;
//}
// if caching and is not an admin controller
if ($this->caching && strpos($this->type, 'admin') !== 0) {
$modulesnocache = explode(',', ModUtil::getVar('Theme', 'modulesnocache'));
if (in_array($this->toplevelmodule, $modulesnocache)) {
$this->caching = Zikula_View::CACHE_DISABLED;
}
} else {
$this->caching = Zikula_View::CACHE_DISABLED;
}
// halt caching for write operations to prevent strange things happening
if (isset($_POST) && count($_POST) != 0) {
$this->caching = Zikula_View::CACHE_DISABLED;
}
// and also for GET operations with csrftoken/authkey
if (isset($_GET['csrftoken']) || isset($_GET['authkey'])) {
$this->caching = Zikula_View::CACHE_DISABLED;
}
$this->cache_lifetime = ModUtil::getVar('Theme', 'cache_lifetime');
if (!$this->homepage) {
$this->cache_lifetime = ModUtil::getVar('Theme', 'cache_lifetime_mods');
}
// assign all our base template variables
$this->_base_vars();
// define the plugin directories
$this->_plugin_dirs();
// load the theme configuration
$this->load_config();
// check for cached output
// turn on caching, check for cached output and then disable caching
// to prevent blocks from being cached
if ($this->caching && $this->is_cached($this->themeconfig['page'], $this->cache_id)) {
$this->display($this->themeconfig['page'], $this->cache_id);
System::shutdown();
}
// register page vars output filter
$this->load_filter('output', 'pagevars');
// register short urls output filter
if (System::getVar('shorturls')) {
$this->load_filter('output', 'shorturls');
}
// register trim whitespace output filter if requried
if (ModUtil::getVar('Theme', 'trimwhitespace')) {
$this->load_filter('output', 'trimwhitespace');
}
$event = new GenericEvent($this);
$this->dispatcher->dispatch('theme.init', $event);
}
/**
* Get Theme instance.
*
* @param string $themeName Theme name.
* @param integer|null $caching Whether or not to cache (Zikula_View::CACHE_*) or use config variable (null).
* @param string $cache_id Cache Id.
*
* @return Zikula_Theme This instance.
*/
public static function getInstance($themeName = '', $caching = null, $cache_id = null)
{
if (!$themeName) {
$themeName = UserUtil::getTheme();
}
$themeName = preg_match('/\w+Theme$/', $themeName) ? $themeName : $themeName.'Theme';
$serviceId = 'zikula.theme';
$container = ServiceUtil::getManager();
if (!$container->has($serviceId)) {
$themeInstance = new self($container, $themeName);
$container->set($serviceId, $themeInstance);
} else {
$themeInstance = $container->get($serviceId);
}
if (!is_null($caching)) {
$themeInstance->caching = $caching;
}
if (!is_null($cache_id)) {
$themeInstance->cache_id = $cache_id;
}
return $themeInstance;
}
/**
* Display the page output.
*
* @return string
*/
public function themefooter($maincontent)
{
// add the module wrapper
if (!$this->themeinfo['system'] && (bool)$this->themeconfig['modulewrapper'] && $this->toplevelmodule) {
$maincontent = '<div id="z-maincontent" class="'.($this->homepage ? 'z-homepage ' : '').'z-module-' . DataUtil::formatForDisplay(strtolower($this->toplevelmodule)) . '">' . $maincontent . '</div>';
}
$event = new GenericEvent($this, array(), $maincontent);
$this->dispatcher->dispatch('theme.prefetch', $event);
$maincontent = $event->getData();
// Assign the main content area to the template engine
$this->assign('maincontent', $maincontent);
// render the page using the correct template
$output = $this->fetch($this->themeconfig['page'], $this->cache_id);
$event = new GenericEvent($this, array(), $output);
$this->dispatcher->dispatch('theme.postfetch', $event);
return $event->getData();
}
/**
* Display a block.
*
* @param array $block Block information.
*
* @return string The rendered output.
*/
public function themesidebox($block)
{
// assign the block information
$this->assign($block);
$bid = $block['bid'];
$bkey = strtolower($block['bkey']);
$position = strtolower($block['position']);
// fix block positions - for now....
if ($position == 'l') {
$position = 'left';
}
if ($position == 'c') {
$position = 'center';
}
if ($position == 'r') {
$position = 'right';
}
// HACK: Save/restore output filters - we don't want to output-filter blocks
$outputfilters = $this->_plugins['outputfilter'];
$this->_plugins['outputfilter'] = array();
// HACK: Save/restore cache settings
$caching = $this->caching;
$this->caching = Zikula_View::CACHE_DISABLED;
$return = '';
// determine the correct template and construct the output
if (isset($this->themeconfig['blockinstances'][$bid]) && !empty($this->themeconfig['blockinstances'][$bid])) {
$return .= $this->fetch($this->themeconfig['blockinstances'][$bid]);
} elseif (isset($this->themeconfig['blocktypes'][$bkey]) && !empty($this->themeconfig['blocktypes'][$bkey])) {
$return .= $this->fetch($this->themeconfig['blocktypes'][$bkey]);
} elseif (isset($this->themeconfig['blockpositions'][$position]) && !empty($this->themeconfig['blockpositions'][$position])) {
$return .= $this->fetch($this->themeconfig['blockpositions'][$position]);
} elseif (!empty($this->themeconfig['block'])) {
$return .= $this->fetch($this->themeconfig['block']);
} else {
if (!empty($block['title'])) {
$return .= '<h4>' . DataUtil::formatForDisplayHTML($block['title']) . ' ' . $block['minbox'] . '</h4>';
}
$return .= $block['content'];
}
// HACK: Save/restore output filters
$this->_plugins['outputfilter'] = $outputfilters;
// HACK: Save/restore cache settings
$this->caching = $caching;
if ((bool)$this->themeconfig['blockwrapper']) {
$return = '<div class="z-block z-blockposition-' . DataUtil::formatForDisplay($block['position']) . ' z-bkey-' . DataUtil::formatForDisplay(strtolower($block['bkey'])) . ' z-bid-' . DataUtil::formatForDisplay($block['bid']) . '">' . "\n" . $return . "</div>\n";
}
return $return;
}
/**
* Checks which path to use for required template.
*
* @param string $template The template name.
*
* @return string Template path.
*/
public function get_template_path($template)
{
if (isset($this->templateCache[$template])) {
return $this->templateCache[$template];
}
// get the theme path to templates
$themeDir = DataUtil::formatForOS($this->directory);
$osTemplate = DataUtil::formatForOS($template);
if (is_dir("themes/$themeDir/Resources/view")) {
$relativePath = "themes/$themeDir/Resources/view";
}
$templateFile = "$relativePath/$osTemplate";
$override = self::getTemplateOverride($templateFile);
if ($override === false) {
if (is_readable($templateFile)) {
$this->templateCache[$template] = $relativePath;
return $relativePath;
} else {
return false;
}
} else {
if (is_readable($override)) {
$path = substr($override, 0, strrpos($override, $osTemplate));
$this->templateCache[$template] = $path;
return $path;
}
}
// when we arrive here, no path was found
return false;
}
/**
* Define all our plugin directories.
*
* @return void
*/
private function _plugin_dirs()
{
// add theme specific plugins directories, if they exist
$this->addPluginDir('themes/' . $this->directory . '/Resources/view/plugins');
}
/**
* Clears the cache for a specific cache_id's in all active themes.
*
* @param string $cache_ids Array of given cache ID's for which to clear theme cache.
* @param string $themes Array of theme objects for which to clear theme cache, defaults to all active themes.
*
* @return boolean True on success.
*/
public function clear_cacheid_allthemes($cache_ids, $themes = null)
{
if ($cache_ids) {
if (!is_array($cache_ids)) {
$cache_ids = array($cache_ids);
}
if (!$themes) {
$themes = ThemeUtil::getAllThemes();
}
$theme = Zikula_View_Theme::getInstance();
foreach ($themes as $themearr) {
foreach ($cache_ids as $cache_id) {
$theme->clear_cache(null, $cache_id, null, null, $themearr['directory']);
}
}
}
return true;
}
/**
* Get a concrete filename for automagically created content.
*
* Generates a filename path like: Theme / auto_id [/ source_dir / filename-l{lang}.ext]
* the final part gets generated only if $auto_source is specified.
*
* @param string $path The base path.
* @param string $auto_source The file name (optional).
* @param string $auto_id The ID (optional).
*
* @return string The concrete path and file name to the content.
*/
function _get_auto_filename($path, $auto_source = null, $auto_id = null, $themedir = null)
{
// enables a flags to detect when is treating compiled templates
$tocompile = ($path == $this->compile_dir) ? true : false;
// format auto_source for os to make sure that id does not contain 'ugly' characters
$auto_source = DataUtil::formatForOS($auto_source);
// add the Theme name as first folder
if (empty($themedir)) {
$path .= '/' . $this->directory;
} else {
$path .= '/' . $themedir;
}
// the last folder is the cache_id if set
$path .= !empty($auto_id) ? '/' . $auto_id : '';
// takes in account the source subdirectory
$path .= strpos($auto_source, '/') !== false ? '/' . dirname($auto_source) : '';
// make sure the path exists to write the compiled/cached template there
if (!file_exists($path)) {
mkdir($path, $this->container['system.chmod_dir'], true);
}
// if there's a explicit source, it
if ($auto_source) {
$path .= '/';
$extension = FileUtil::getExtension($auto_source);
// isolates the filename on the source path passed
$path .= FileUtil::getFilebase($auto_source);
// if we are compiling we do not include cache variables
if (!$tocompile) {
// add the variable stuff only if $auto_source is present
// to allow a easy flush cache for all the languages (if needed)
$path .= '-l';
if (System::getVar('multilingual') == 1) {
$path .= $this->language;
}
// end with a suffix convention of filename--Themename-lang.ext
$path .= ($extension ? ".$extension" : '');
}
}
return $path;
}
/**
* Assign template vars for base theme paths and other useful variables.
*
* @return void
*/
private function _base_vars()
{
// identify the page type
$this->pagetype = 'module';
if ((stristr(System::serverGetVar('PHP_SELF'), 'admin.php') || strtolower($this->type) == 'admin')) {
$this->pagetype = 'admin';
} elseif (empty($module)) {
$this->pagetype = 'home';
}
// set some basic class variables from Zikula
$this->isloggedin = UserUtil::isLoggedIn();
$this->uid = UserUtil::getVar('uid');
// assign the query string
$this->qstring = System::serverGetVar('QUERY_STRING', '');
// assign the current script
$this->requesturi = System::getCurrentUri();
// define the cache_id if not set yet
if ($this->caching && !$this->cache_id) {
// module / type / function / customargs|homepage/startpageargs / uid_X|guest
$this->cache_id = $this->toplevelmodule . '/' . $this->type . '/' . $this->func
. (!$this->homepage ? $this->_get_customargs() : '/homepage/' . str_replace(',', '/', System::getVar('startargs')))
. '/' . UserUtil::getUidCacheString();
}
// assign some basic paths for the engine
$this->template_dir = $this->themepath . '/templates'; // default directory for templates
$this->themepath = 'themes/' . $this->directory;
$this->imagepath = $this->themepath . '/Resources/public/images';
$this->imagelangpath = $this->themepath . '/Resources/public/images/' . $this->language;
$this->stylepath = $this->themepath . '/Resources/public/css';
$this->scriptpath = $this->themepath . '/Resources/public/js';
// make the base vars available to all templates
$this->assign('module', $this->toplevelmodule)
->assign('uid', $this->uid)
->assign('loggedin', $this->isloggedin)
->assign('pagetype', $this->pagetype)
->assign('themepath', $this->themepath)
->assign('imagepath', $this->imagepath)
->assign('imagelangpath', $this->imagelangpath)
->assign('stylepath', $this->stylepath)
->assign('scriptpath', $this->scriptpath);
// load the theme variables
$variables = ModUtil::apiFunc('ThemeModule', 'user', 'getvariables', array('theme' => $this->name));
$this->assign($variables['variables']);
}
/**
* Normalizes the current page parameters.
*
* Used on the page cache_id and the pageassignments keys.
*
* @return string Custom arguments string.
*/
private function _get_customargs()
{
static $customargs;
if (isset($customargs)) {
return $customargs;
}
// parse the query string into individual arguments discarding common arguments
// common arguments are ones that we don't want affecting our url matching or ones that are
// already considered; These are same args defined as reserved by the MDG.
$customargs = '';
if ($this->pagetype != 'admin' && System::getVar('shorturls')) {
// remove the base URI and the entrypoint from the request URI
$customargs = str_replace(System::getBaseUri(), '', $this->requesturi);
$entrypoint = System::getVar('entrypoint');
$customargs = str_replace("/{$entrypoint}/", '/', $customargs);
$customargs = ($customargs == '/') ? '' : $customargs;
} else {
$queryparts = explode('&', $this->qstring);
foreach ($queryparts as $querypart) {
if (!stristr($querypart, 'module=') && !stristr($querypart, 'type=') && !stristr($querypart, 'func=') && !stristr($querypart, 'theme=') && !stristr($querypart, 'authid=') && !stristr($querypart, 'csrftoken=')) {
$customargs .= '/' . $querypart;
}
}
}
return $customargs;
}
/**
* Load the base theme configuration.
*
* Can be used into the system but if the themeconfig['page'] is changed the cache
* gets canceled because there will be no match between initial cache_id and default page.
* Try to change only theme variables that changes the behaviour of the output.
*
* @return void
*/
public function load_config()
{
if (!$this->themeconfig) {
// load the page configurations
$pageconfigurations = ModUtil::apiFunc('ThemeModule', 'user', 'getpageconfigurations', array('theme' => $this->name));
// identify and load the correct module configuration
// checks homepage match
if ($this->homepage && isset($pageconfigurations['*home'])) {
// allow us to match any non-zikula query string
$homeWithArgs = 'home' . '/' . $this->qstring;
if (isset($pageconfigurations[$homeWithArgs])) {
$file = $pageconfigurations[$homeWithArgs]['file'];
} else {
$file = $pageconfigurations['*home']['file'];
}
$file = $pageconfigurations['*home']['file'];
// identify a type match
} elseif (isset($pageconfigurations['*'.$this->type])) {
$file = $pageconfigurations['*'.$this->type]['file'];
// identify an admin-like type
} else if (strpos($this->type, 'admin') === 0 && isset($pageconfigurations['*admin'])) {
$file = $pageconfigurations['*admin']['file'];
// search for arguments match
} else {
$customargs = $this->toplevelmodule . '/' . $this->type . '/' . $this->func . $this->_get_customargs();
// find any page configurations that match in a sub string comparison
$match = '';
$matchlength = 0;
foreach (array_keys($pageconfigurations) as $pageconfiguration) {
if (stristr($customargs, $pageconfiguration) && $matchlength < strlen($pageconfiguration)) {
$match = $pageconfiguration;
$matchlength = strlen($match);
if (isset($pageconfigurations[$pageconfiguration]['important']) && $pageconfigurations[$pageconfiguration]['important']) {
break;
}
}
}
if (!empty($match)) {
$file = $pageconfigurations[$match]['file'];
}
}
if (empty($file)) {
$file = $pageconfigurations['master']['file'];
}
// load the page configuration
$this->themeconfig = ModUtil::apiFunc('ThemeModule', 'user', 'getpageconfiguration', array('theme' => $this->name, 'filename' => $file));
// check if we've not got a valid theme configation
if (!$this->themeconfig['page']) {
$file = 'master.ini';
$this->themeconfig = ModUtil::apiFunc('ThemeModule', 'user', 'getpageconfiguration', array('theme' => $this->name, 'filename' => $file));
}
}
if (empty($this->themeconfig['page'])) {
throw new Exception(__f("Empty 'page' specified in your theme page configuration on file %s.", array($file)));
}
// register any filters
if (!empty($this->themeconfig['filters'])) {
// check for output filters
if (isset($this->themeconfig['filters']['outputfilters']) && !empty($this->themeconfig['filters']['outputfilters'])) {
$filters = $this->themeconfig['filters']['outputfilters'];
$filters = !is_array($filters) ? explode(',', $filters) : $filters;
foreach ($filters as $filter) {
$this->load_filter('output', $filter);
}
}
// check for pre filters
if (isset($this->themeconfig['filters']['prefilters']) && !empty($this->themeconfig['filters']['prefilters'])) {
$filters = $this->themeconfig['filters']['prefilters'];
$filters = !is_array($filters) ? explode(',', $filters) : $filters;
foreach ($filters as $filter) {
$this->load_filter('pre', $filter);
}
}
// check for post filters
if (isset($this->themeconfig['filters']['postfilters']) && !empty($this->themeconfig['filters']['postfilters'])) {
$filters = $this->themeconfig['filters']['postfilters'];
$filters = !is_array($filters) ? explode(',', $filters) : $filters;
foreach ($filters as $filter) {
$this->load_filter('post', $filter);
}
}
}
// load the pageconfiguration variables
if (!empty($this->themeconfig['variables'])) {
$this->assign($this->themeconfig['variables']);
}
// load the palette if set
if (!empty($this->themeconfig['palette'])) {
$palette = ModUtil::apiFunc('ThemeModule', 'user', 'getpalette', array('theme' => $this->name, 'palette' => $this->themeconfig['palette']));
$this->assign('palette', $palette);
}
$event = new GenericEvent($this);
$this->dispatcher->dispatch('theme.load_config', $event);
}
/**
* Template override handler for 'zikula_view.template_override'.
*
* @param GenericEvent $event Event handler.
*
* @return void
*/
public function _templateOverride(GenericEvent $event)
{
if (array_key_exists($event->data, $this->_overrideMap)) {
$event->data = $this->_overrideMap[$event->data];
$event->stopPropagation();
}
}
/**
* Clear CSS/JS combination cached files.
*
* Using this function, the user can clear all CSS/JS combination cached
* files for the system.
*
* @return boolean
*/
public function clear_cssjscombinecache()
{
$cache_dir = $this->cache_dir;
$cached_files = FileUtil::getFiles($cache_dir, true, false, array('php'), null, false);
foreach ($cached_files as $cf) {
unlink(realpath($cf));
}
// The configuration has been changed, so we clear all caches.
// clear Zikula_View_Theme cache
self::clear_all_cache();
// clear Zikula_View cache (really needed?)
Zikula_View::getInstance()->clear_all_cache();
return true;
}
/**
* Clears the Theme configuration located on the temporary directory.
*
* @return boolean True on success, false otherwise.
*/
public function clear_theme_config()
{
$configdir = CacheUtil::getLocalDir('Theme_Config');
return $this->clear_folder($configdir, null, null, null);
}
/**
* Retrieve the name of the theme.
*
* @return string The name.
*/
public function getName()
{
return $this->name;
}
/**
* Retrieve the theme directory name.
*
* @return <type>
*/
public function getDirectory()
{
return $this->directory;
}
/**
* Retrieve the theme's version string.
*
* @return string The version of the theme.
*/
public function getVersion()
{
return $this->version;
}
/**
* Retrieve the state of the theme.
*
* Values:
* <ul>
* <li>ThemeUtil::STATE_ACTIVE</li>
* <li>ThemeUtil::STATE_INACTIVE</li>
* <li>ThemeUtil::STATE_ALL</li>
* </ul>
*
* @return integer The theme's state.
*/
public function getState()
{
return $this->state;
}
/**
* Indicates whether the theme is an XHTML-based theme or an HTML-based theme.
*
* @return integer 1 for XHTML-capable, otherwise HTML.
*/
public function getXhtml()
{
return $this->xhtml;
}
/**
* Retrieve the path to the theme.
*
* @return string The path to the theme.
*/
public function getThemePath()
{
return $this->themepath;
}
/**
* Retrieve the path to the theme's images.
*
* @return string The path to the theme's images.
*/
public function getImagePath()
{
return $this->imagepath;
}
/**
* Retrieve the path to the theme's language-specific images.
*
* @return string The path to the theme's language-specific images.
*/
public function getImageLangPath()
{
return $this->imagelangpath;
}
/**
* Retrieve the path to the theme's stylesheets.
*
* @return string The path to the theme's stylesheets.
*/
public function getStylePath()
{
return $this->stylepath;
}
/**
* Retrieve the path to the theme's javascript files.
*
* @return string The path to the theme's javascript files.
*/
public function getScriptPath()
{
return $this->scriptpath;
}
/**
* Retrieve the theme configuration.
*
* @return array The contents of the theme configuration (or the master configuration).
*/
public function getThemeConfig()
{
return $this->themeconfig;
}
/**
* Indicates whether this is a home page or not.
*
* @return boolean True if this is a home page (module name is empty), otherwise false.
*/
public function isHomePage()
{
return $this->homepage;
}
/**
* Retrieve the current user's uid.
*
* @return numeric The current user's uid.
*/
public function getUid()
{
return $this->uid;
}
/**
* Indicates whether the current user is logged in.
*
* @return boolean True if the current user is logged in, false if the current user is anonymous (a guest).
*/
public function getIsLoggedIn()
{
return $this->isloggedin;
}
/**
* The current page's type.
*
* @return string One of 'module', 'admin' or 'home'.
*/
public function getPageType()
{
return $this->pagetype;
}
/**
* Retrieve the query string for the current page request.
*
* @return string The query string for the current request.
*/
public function getQstring()
{
return $this->qstring;
}
/**
* Retrieve the current page's request URI.
*
* @return string The current page's request URI.
*/
public function getRequestUri()
{
return $this->requesturi;
}
/**
* Set the current cache ID.
*
* @param string $cache_id Cache ID to set.
*
* @return void
*/
public function setCacheId($cache_id)
{
$this->cache_id = $cache_id;
}
/**
* Set the theme configuration.
*
* @param array $themeconfig Theme configuration array to set.
*
* @return void
*/
public function setThemeConfig($themeconfig)
{
if ($themeconfig && is_array($themeconfig)) {
$this->themeconfig = $themeconfig;
}