/
PageOutput.php
982 lines (841 loc) · 29.3 KB
/
PageOutput.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
<?php
/**
* This object consolidates the elements needed to output a page to the
* browser.
*
* Copyright 2012-2014 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Core
*/
class Horde_PageOutput
{
/**
* Output code necessary to perform AJAX operations?
*
* @var boolean
*/
public $ajax = false;
/**
* Stylesheet object.
*
* @var Horde_Themes_Css
*/
public $css;
/**
* Activate debugging output.
*
* @internal
*
* @var boolean
*/
public $debug = false;
/**
* Defer loading of scripts until end of page?
*
* @var boolean
*/
public $deferScripts = true;
/**
* Output code necessary to display growler notifications?
*
* @var boolean
*/
public $growler = false;
/**
* Script list.
*
* @var Horde_Script_List
*/
public $hsl;
/**
* List of inline scripts.
*
* @var array
*/
public $inlineScript = array();
/**
* List of LINK tags to output.
*
* @var array
*/
public $linkTags = array();
/**
* List of META tags to output.
*
* @var array
*/
public $metaTags = array();
/**
* Load the sidebar in this page?
*
* @var boolean
*/
public $sidebar = true;
/**
* Smartmobile init code that needs to be output before jquery.mobile.js
* is loaded.
*
* @since 2.12.0
*
* @var array
*/
public $smartmobileInit = array();
/**
* Load the topbar in this page?
*
* @var boolean
*/
public $topbar = true;
/**
* Has PHP userspace page compression been started?
*
* @var boolean
*/
protected $_compress = false;
/**
* View mode.
*
* @var integer
*/
protected $_view = 0;
/**
* Constructor.
*/
public function __construct()
{
$this->css = new Horde_Themes_Css();
$this->hsl = new Horde_Script_List();
}
/**
* Adds a single javascript script to the output (if output has already
* started), or to the list of script files to include in the output.
*
* @param mixed $file Either a Horde_Script_File object, or the full
* javascript file name.
* @param string $app If $file is a file name, this is the application
* where the file is located. Defaults to the current
* registry application.
*
* @return Horde_Script_File Script file object.
*/
public function addScriptFile($file, $app = null)
{
$ob = is_object($file)
? $file
: new Horde_Script_File_JsDir($file, $app);
return $this->hsl->add($ob);
}
/**
* Adds a javascript package to the browser output.
*
* @param mixed $package Either a classname, basename of a
* Horde_Core_Script_Package class, or a
* Horde_Script_Package object.
*
* @return Horde_Script_Package Package object.
* @throws Horde_Exception
*/
public function addScriptPackage($package)
{
if (!is_object($package)) {
if (!class_exists($package)) {
$package = 'Horde_Core_Script_Package_' . $package;
if (!class_exists($package)) {
throw new Horde_Exception('Invalid package name provided.');
}
}
$package = new $package();
}
foreach ($package as $ob) {
$this->hsl->add($ob);
}
return $package;
}
/**
* Outputs the necessary script tags, honoring configuration choices as
* to script caching.
*
* @throws Horde_Exception
*/
public function includeScriptFiles()
{
global $browser, $conf;
if (!$browser->hasFeature('javascript')) {
return;
}
if (!empty($this->smartmobileInit)) {
echo Horde::wrapInlineScript(array(
'var horde_jquerymobile_init = function() {' .
implode('', $this->_martmobileInit) . '};'
));
$this->smartmobileInit = array();
}
$all_scripts = $jsvars = $tmp = array();
$driver = empty($conf['cachejs'])
? 'none'
: strtolower($conf['cachejsparams']['driver']);
$last_cache = null;
foreach ($this->hsl as $val) {
if ($driver == 'none') {
echo $val;
} elseif (is_null($val->cache)) {
if (!empty($tmp)) {
$this->_outputCachedScripts($tmp);
$tmp = array();
}
echo $val;
} else {
if (!is_null($last_cache) && ($last_cache != $val->cache)) {
$this->_outputCachedScripts($tmp);
$tmp = array();
}
$tmp[$val->hash] = $val;
}
$last_cache = $val->cache;
if (!empty($val->jsvars)) {
$jsvars = array_merge($jsvars, $val->jsvars);
}
$all_scripts[] = strval($val->url);
}
if (($this->ajax || $this->growler) && $all_scripts) {
$jsvars['HordeCore.jsfiles'] = $all_scripts;
}
$this->_outputCachedScripts($tmp);
$this->hsl->clear();
$this->addInlineJsVars($jsvars);
}
/**
*/
protected function _outputCachedScripts($scripts)
{
global $conf, $injector, $registry;
if (empty($scripts)) {
return;
}
$mtime = 0;
foreach ($scripts as $val) {
if (($tmp = $val->modified) > $mtime) {
$mtime = $tmp;
}
}
$hashes = array_keys($scripts);
sort($hashes);
$sig = hash('sha1', serialize($hashes) . $mtime);
$driver = empty($conf['cachejs'])
? 'none'
: strtolower($conf['cachejsparams']['driver']);
switch ($driver) {
case 'filesystem':
$js_filename = '/static/' . $sig . '.js';
$js_path = $registry->get('fileroot', 'horde') . $js_filename;
$js_url = $registry->get('webroot', 'horde') . $js_filename;
$sourcemap_url = $js_url . '.map';
$exists = file_exists($js_path);
break;
case 'horde_cache':
$cache = $injector->getInstance('Horde_Cache');
$cache_lifetime = empty($conf['cachejsparams']['lifetime'])
? 0
: $conf['cachejsparams']['lifetime'];
// Do lifetime checking here, not on cache display page.
$exists = $cache->exists($sig, $cache_lifetime);
$js_url = Horde::getCacheUrl('js', array('cid' => $sig));
$sourcemap_url = Horde::getCacheUrl('js', array('cid' => $sig . '.map'));
break;
}
echo '<script type="text/javascript" src="' . $js_url . '"></script>';
if ($exists) {
return;
}
/* Check for existing process creating file. Maximum 15 seconds
* wait time. */
for ($i = 0; $i < 15; ++$i) {
switch ($driver) {
case 'filesystem':
if (file_exists($js_path . '.lock')) {
sleep(1);
} elseif ($i) {
return;
} else {
touch($js_path . '.lock');
break 2;
}
break;
case 'horde_cache':
if ($cache->exists($sig . '.lock')) {
sleep(1);
} elseif ($i) {
return;
} else {
$cache->set($sig . '.lock', 1);
break 2;
}
break;
}
}
$jsmin_params = array(
'logger' => $injector->getInstance('Horde_Log_Logger')
);
switch ($conf['cachejsparams']['compress']) {
case 'closure':
$jsmin = 'Horde_JavascriptMinify_Closure';
$jsmin_params = array_merge($jsmin_params, array(
'closure' => $conf['cachejsparams']['closurepath'],
'java' => $conf['cachejsparams']['javapath'],
'sourcemap' => $sourcemap_url
));
break;
case 'none':
$jsmin = 'Horde_JavascriptMinify_Null';
break;
case 'php':
/* Due to licensing issues, Jsmin might not be available. */
$jsmin = class_exists('Horde_JavascriptMinify_Jsmin')
? 'Horde_JavascriptMinify_Jsmin'
: 'Horde_JavascriptMinify_Null';
break;
case 'uglifyjs':
$jsmin = 'Horde_JavascriptMinify_Uglifyjs';
$jsmin_params = array_merge($jsmin_params, array(
'cmdline' => $conf['cachejsparams']['uglifyjscmdline'],
'sourcemap' => $sourcemap_url,
'uglifyjs' => $conf['cachejsparams']['uglifyjspath']
));
break;
case 'yui':
$jsmin = 'Horde_JavascriptMinify_Yui';
$jsmin_params = array_merge($jsmin_params, array(
'java' => $conf['cachejsparams']['javapath'],
'yui' => $conf['cachejsparams']['yuipath']
));
break;
default:
/* Treat as a custom driver. */
if (class_exists($conf['cachejsparams']['compress'])) {
$jsmin = $conf['cachejsparams']['compress'];
$jsmin_params = array_merge($jsmin_params, $conf['cachejsparams']);
} else {
$jsmin = 'Horde_JavascriptMinify_Null';
}
break;
}
$js_files = array();
foreach ($scripts as $val) {
$js_files[strval($val->url_full)] = $val->full_path;
}
$jsmin_ob = new $jsmin($js_files, $jsmin_params);
$js_text = $jsmin_ob->minify();
switch ($driver) {
case 'filesystem':
if (!file_put_contents($js_path, $js_text)) {
Horde::log('Could not write cached JS file to disk.', Horde_Log::EMERG);
} elseif (isset($jsmin_params['sourcemap'])) {
file_put_contents($js_path . '.map', $jsmin_ob->sourcemap());
}
unlink($js_path . '.lock');
break;
case 'horde_cache':
$cache->set($sig, $js_text);
if (isset($jsmin_params['sourcemap'])) {
$cache->set($sig . '.map', $jsmin_ob->sourcemap());
}
$cache->expire($sig . '.lock');
break;
}
}
/**
* Add inline javascript to the output buffer.
*
* @param mixed $script The script text to add (can be stored in an
* array).
* @param boolean $onload Load the script after the page (DOM) has
* loaded?
* @param boolean $top Add script to top of stack?
*/
public function addInlineScript($script, $onload = false, $top = false)
{
$script = is_array($script)
? implode(';', array_map('trim', $script))
: trim($script);
if (!strlen($script)) {
return;
}
$onload = intval($onload);
$script = rtrim($script, ';') . ';';
if ($top && isset($this->inlineScript[$onload])) {
array_unshift($this->inlineScript[$onload], $script);
} else {
$this->inlineScript[$onload][] = $script;
}
// If headers have already been sent, we need to output a
// <script> tag directly.
if (!$this->deferScripts && Horde::contentSent()) {
$this->outputInlineScript();
}
}
/**
* Add inline javascript variable definitions to the output buffer.
*
* @param array $data Keys are the variable names, values are the data
* to JSON encode. If the key begins with a '-',
* the data will be added to the output as-is.
* @param mixed $opts If boolean true, equivalent to setting the 'onload'
* option to true. Other options:
* - onload: (boolean) Wrap the definition in an onload handler?
* DEFAULT: false
* - ret_vars: (boolean) If true, will return the list of variable
* definitions instead of outputting to page.
* DEFAULT: false
* - top: (boolean) Add definitions to top of stack?
* DEFAULT: false
*
* @return array Returns the variable list of 'ret_vars' option is true.
*/
public function addInlineJsVars($data, $opts = array())
{
$out = array();
if ($opts === true) {
$opts = array('onload' => true);
}
$opts = array_merge(array(
'onload' => false,
'ret_vars' => false,
'top' => false
), $opts);
foreach ($data as $key => $val) {
if ($key[0] == '-') {
$key = substr($key, 1);
} else {
$val = Horde_Serialize::serialize($val, Horde_Serialize::JSON);
}
$out[] = $key . '=' . $val;
}
if ($opts['ret_vars']) {
return $out;
}
$this->addInlineScript($out, $opts['onload'], $opts['top']);
}
/**
* Print pending inline javascript to the output buffer.
*
* @param boolean $raw Return the raw script (not wrapped in CDATA tags
* or observe wrappers)?
*/
public function outputInlineScript($raw = false)
{
if (empty($this->inlineScript)) {
return;
}
$script = array();
foreach ($this->inlineScript as $key => $val) {
$val = implode('', $val);
$script[] = (!$raw && $key)
? 'document.observe("dom:loaded",function(){' . $val . '});'
: $val;
}
echo $raw
? implode('', $script)
: Horde::wrapInlineScript($script);
$this->inlineScript = array();
}
/**
* Generate and output the favicon tag for the current application.
*/
public function includeFavicon()
{
$img = strval(Horde_Themes::img('favicon.ico', array(
'nohorde' => true
)));
if (!$img) {
$img = strval(Horde_Themes::img('favicon.ico', array(
'app' => 'horde'
)));
}
echo '<link type="image/x-icon" href="' . $img . '" rel="SHORTCUT ICON" />';
}
/**
* Adds a META tag to the page output.
*
* @param string $name The name value.
* @param string $content The content of the META tag.
* @param boolean $http_equiv Output http-equiv instead of name?
*/
public function addMetaTag($name, $content, $http_equiv = true)
{
$this->metaTags[$name] = array(
'c' => $content,
'h' => $http_equiv
);
}
/**
* Adds a META refresh tag.
*
* @param integer $time Refresh time.
* @param string $url Refresh URL
*/
public function metaRefresh($time, $url)
{
if (!empty($time) && !empty($url)) {
$this->addMetaTag('refresh', $time . ';url=' . $url);
}
}
/**
* Adds a META tag to disable DNS prefetching.
* See Horde Bug #8836.
*/
public function noDnsPrefetch()
{
$this->addMetaTag('x-dns-prefetch-control', 'off');
}
/**
* Output META tags to page.
*/
public function outputMetaTags()
{
foreach ($this->metaTags as $key => $val) {
echo '<meta content="' . $val['c'] . '" ' .
($val['h'] ? 'http-equiv' : 'name') .
'="' . $key . "\" />\n";
}
$this->metaTags = array();
}
/**
* Adds a LINK tag.
*
* All attributes are HTML-encoded. Only pass raw, unencoded attribute
* values to avoid double escaping.
*
* @param array $opts Non-default tag elements.
*/
public function addLinkTag(array $opts = array())
{
$opts = array_merge(array(
'rel' => 'alternate',
'type' => 'application/rss+xml'
), $opts);
$out = '<link';
foreach ($opts as $key => $val) {
if (!is_null($val)) {
$out .= ' ' . $key . '="' . htmlspecialchars($val) . '"';
}
}
$this->linkTags[] = $out . ' />';
}
/**
* Output LINK tags.
*/
public function outputLinkTags()
{
echo implode("\n", $this->linkTags);
$this->linkTags = array();
}
/**
* Adds an external stylesheet to the output.
*
* @param Horde_Themes_Element|string $file Either a Horde_Themes_Element
* object or the CSS filepath.
* @param string $url If $file is a string, this
* must be a CSS URL.
*/
public function addStylesheet($file, $url = null)
{
if ($file instanceof Horde_Themes_Element) {
$url = $file->uri;
$file = $file->fs;
}
$this->css->addStylesheet($file, $url);
}
/**
* Adds a themed stylesheet to the output.
*
* @param string $file The stylesheet name.
*/
public function addThemeStylesheet($file)
{
$this->css->addThemeStylesheet($file);
}
/**
* Generate the stylesheet tags for the current application.
*
* @param array $opts Options to pass to
* Horde_Themes_Css::getStylesheetUrls().
* @param array $full Return a full URL?
*/
public function includeStylesheetFiles(array $opts = array(),
$full = false)
{
foreach ($this->css->getStylesheetUrls($opts) as $val) {
echo '<link href="' . $val->toString(false, $full) . '" rel="stylesheet" type="text/css" />';
}
}
/**
* Activates output compression.
*/
public function startCompression()
{
if ($this->_compress) {
return;
}
/* Compress output if requested and possible. */
if ($GLOBALS['conf']['compress_pages'] &&
!$GLOBALS['browser']->hasQuirk('buggy_compression') &&
!(bool)ini_get('zlib.output_compression') &&
!(bool)ini_get('zend_accelerator.compress_all') &&
ini_get('output_handler') != 'ob_gzhandler') {
if (ob_get_level()) {
ob_end_clean();
}
ob_start('ob_gzhandler');
}
$this->_compress = true;
}
/**
* Disables output compression. If successful, throws out all data
* currently in the output buffer. Must be called before any data is sent
* to the browser.
*/
public function disableCompression()
{
if ($this->_compress && (reset(ob_list_handlers()) == 'ob_gzhandler')) {
ob_end_clean();
/* Removing the ob_gzhandler ADDS the below headers, which breaks
* display on the browser (as of PHP 5.3.15). */
header_remove('content-encoding');
header_remove('vary');
$this->_compress = false;
}
}
/**
* Output the page header.
*
* @param array $opts Options:
* - body_class: (string)
* - body_id: (string)
* - html_id: (string)
* - smartmobileinit: (string) (@deprecated; use $this->smartmobileInit
* instead)
* - stylesheet_opts: (array)
* - title: (string)
* - view: (integer)
*/
public function header(array $opts = array())
{
global $injector, $language, $registry, $session;
$view = new Horde_View(array(
'templatePath' => $registry->get('templates', 'horde') . '/common'
));
$view->outputJs = !$this->deferScripts;
$view->stylesheetOpts = array();
$this->_view = empty($opts['view'])
? ($registry->hasView($registry->getView()) ? $registry->getView() : Horde_Registry::VIEW_BASIC)
: $opts['view'];
if ($session->regenerate_due) {
$session->regenerate();
}
switch ($this->_view) {
case $registry::VIEW_BASIC:
$this->_addBasicScripts();
break;
case $registry::VIEW_DYNAMIC:
$this->ajax = true;
$this->growler = true;
$this->_addBasicScripts();
$this->addScriptPackage('Horde_Core_Script_Package_Popup');
break;
case $registry::VIEW_MINIMAL:
$view->stylesheetOpts['subonly'] = true;
$view->minimalView = true;
$this->sidebar = $this->topbar = false;
break;
case $registry::VIEW_SMARTMOBILE:
$smobile_files = array(
($this->debug ? 'jquery.mobile/jquery.js' : 'jquery.mobile/jquery.min.js'),
'growler-jquery.js',
'horde-jquery.js',
'smartmobile.js',
'horde-jquery-init.js',
($this->debug ? 'jquery.mobile/jquery.mobile.js' : 'jquery.mobile/jquery.mobile.min.js')
);
foreach ($smobile_files as $val) {
$this->addScriptFile(new Horde_Script_File_JsFramework($val, 'horde'));
}
$this->smartmobileInit = array_merge(array(
'$.mobile.page.prototype.options.backBtnText = "' . Horde_Core_Translation::t("Back") .'";',
'$.mobile.dialog.prototype.options.closeBtnText = "' . Horde_Core_Translation::t("Close") .'";',
'$.mobile.loader.prototype.options.text = "' . Horde_Core_Translation::t("loading") . '";'
), isset($opts['smartmobileinit']) ? $opts['smartmobileinit'] : array());
$this->addInlineJsVars(array(
'HordeMobile.conf' => array(
'ajax_url' => $registry->getServiceLink('ajax', $registry->getApp())->url,
'logout_url' => strval($registry->getServiceLink('logout')),
'sid' => SID,
'token' => $session->getToken()
)
));
$this->addMetaTag('viewport', 'width=device-width, initial-scale=1', false);
$view->stylesheetOpts['subonly'] = true;
$this->addStylesheet(
$registry->get('jsfs', 'horde') . '/jquery.mobile/jquery.mobile.min.css',
$registry->get('jsuri', 'horde') . '/jquery.mobile/jquery.mobile.min.css'
);
$view->smartmobileView = true;
// Force JS to load at top of page, so we don't see flicker when
// mobile styles are applied.
$view->outputJs = true;
$this->sidebar = $this->topbar = false;
break;
}
$view->stylesheetOpts['sub'] = Horde_Themes::viewDir($this->_view);
if ($this->ajax || $this->growler) {
$this->addScriptFile(new Horde_Script_File_JsFramework('hordecore.js', 'horde'));
/* Configuration used in core javascript files. */
$js_conf = array_filter(array(
/* URLs */
'URI_AJAX' => $registry->getServiceLink('ajax', $registry->getApp())->url,
'URI_DLOAD' => strval($registry->getServiceLink('download', $registry->getApp())),
'URI_LOGOUT' => strval($registry->getServiceLink('logout')),
'URI_SNOOZE' => strval(Horde::url($registry->get('webroot', 'horde') . '/services/snooze.php', true, -1)),
/* Other constants */
'SID' => SID,
'TOKEN' => $session->getToken(),
/* Other config. */
'growler_log' => $this->topbar,
'popup_height' => 610,
'popup_width' => 820
));
/* Gettext strings used in core javascript files. */
$js_text = array(
'ajax_error' => Horde_Core_Translation::t("Error when communicating with the server."),
'ajax_recover' => Horde_Core_Translation::t("The connection to the server has been restored."),
'ajax_timeout' => Horde_Core_Translation::t("There has been no contact with the server for several minutes. The server may be temporarily unavailable or network problems may be interrupting your session. You will not see any updates until the connection is restored."),
'snooze' => sprintf(Horde_Core_Translation::t("You can snooze it for %s or %s dismiss %s it entirely"), '#{time}', '#{dismiss_start}', '#{dismiss_end}'),
'snooze_select' => array(
'0' => Horde_Core_Translation::t("Select..."),
'5' => Horde_Core_Translation::t("5 minutes"),
'15' => Horde_Core_Translation::t("15 minutes"),
'60' => Horde_Core_Translation::t("1 hour"),
'360' => Horde_Core_Translation::t("6 hours"),
'1440' => Horde_Core_Translation::t("1 day")
),
'dismissed' => Horde_Core_Translation::t("The alarm was dismissed.")
);
if ($this->topbar) {
$js_text['growlerinfo'] = Horde_Core_Translation::t("This is the notification log.");
$js_text['growlernoalerts'] = Horde_Core_Translation::t("No Alerts");
}
$this->addInlineJsVars(array(
'HordeCore.conf' => $js_conf,
'HordeCore.text' => $js_text
), array('top' => true));
}
if ($this->growler) {
$this->addScriptFile('growler.js', 'horde');
$this->addScriptFile('scriptaculous/effects.js', 'horde');
$this->addScriptFile('scriptaculous/sound.js', 'horde');
}
if (isset($opts['stylesheet_opts'])) {
$view->stylesheetOpts = array_merge($view->stylesheetOpts, $opts['stylesheet_opts']);
}
$html = '';
if (isset($language)) {
$html .= ' lang="' . htmlspecialchars(strtr($language, '_', '-')) . '"';
}
if (isset($opts['html_id'])) {
$html .= ' id="' . htmlspecialchars($opts['html_id']) . '"';
}
$view->htmlAttr = $html;
$body = '';
if (isset($opts['body_class'])) {
$body .= ' class="' . htmlspecialchars($opts['body_class']) . '"';
}
if (isset($opts['body_id'])) {
$body .= ' id="' . htmlspecialchars($opts['body_id']) . '"';
}
$view->bodyAttr = $body;
$page_title = $registry->get('name');
if (isset($opts['title'])) {
$page_title .= ' :: ' . $opts['title'];
}
$view->pageTitle = htmlspecialchars($page_title);
$view->pageOutput = $this;
header('Content-type: text/html; charset=UTF-8');
if (isset($language)) {
header('Vary: Accept-Language');
}
echo $view->render('header');
if ($this->topbar) {
echo $injector->getInstance('Horde_View_Topbar')->render();
}
// Send what we have currently output so the browser can start
// loading CSS/JS. See:
// http://developer.yahoo.com/performance/rules.html#flush
echo Horde::endBuffer();
flush();
}
/**
* Add basic framework scripts to the output.
*/
protected function _addBasicScripts()
{
global $prefs;
$base_js = array(
'prototype.js',
'horde.js'
);
foreach ($base_js as $val) {
$ob = $this->addScriptFile(new Horde_Script_File_JsFramework($val, 'horde'));
$ob->cache = 'package_basic';
}
if ($prefs->getValue('widget_accesskey')) {
$this->addScriptFile('accesskeys.js', 'horde');
}
}
/**
* Output files needed for smartmobile mode.
*
* @deprecated
*/
public function outputSmartmobileFiles()
{
}
/**
* Output page footer.
*
* @param array $opts Options:
* - NONE currently
*/
public function footer(array $opts = array())
{
global $browser, $notification, $registry;
$view = new Horde_View(array(
'templatePath' => $registry->get('templates', 'horde') . '/common'
));
if (!$browser->isMobile()) {
$notification->notify(array('listeners' => array('audio')));
}
$view->outputJs = $this->deferScripts;
$view->pageOutput = $this;
switch ($this->_view) {
case $registry::VIEW_MINIMAL:
$view->minimalView = true;
break;
case $registry::VIEW_SMARTMOBILE:
$view->smartmobileView = true;
break;
case $registry::VIEW_BASIC:
$view->basicView = true;
if ($this->sidebar) {
$view->sidebar = Horde::sidebar();
}
break;
}
echo $view->render('footer');
$this->deferScripts = false;
}
}