-
Notifications
You must be signed in to change notification settings - Fork 465
/
template.lib.php
executable file
·1330 lines (1163 loc) · 46.4 KB
/
template.lib.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
/* For licensing terms, see /license.txt */
/**
* Class Template
*
* @author Julio Montoya <gugli100@gmail.com>
* @todo better organization of the class, methods and variables
*
*/
class Template
{
/**
* The Template folder name see main/template
* @var string
*/
public $templateFolder = 'default';
/**
* The theme that will be used: chamilo, public_admin, chamilo_red, etc
* This variable is set from the database
* @var string
*/
public $theme = '';
/**
* @var string
*/
public $preview_theme = '';
public $title = null;
public $show_header;
public $show_footer;
public $help;
public $menu_navigation = array(); //Used in the userportal.lib.php function: return_navigation_course_links()
public $show_learnpath = false; // This is a learnpath section or not?
public $plugin = null;
public $course_id = null;
public $user_is_logged_in = false;
public $twig = null;
/* Loads chamilo plugins */
public $load_plugins = false;
public $params = array();
public $force_plugin_load = false;
/**
* @param string $title
* @param bool $show_header
* @param bool $show_footer
* @param bool $show_learnpath
* @param bool $hide_global_chat
* @param bool $load_plugins
* @param bool $sendHeaders send http headers or not
*/
public function __construct(
$title = '',
$show_header = true,
$show_footer = true,
$show_learnpath = false,
$hide_global_chat = false,
$load_plugins = true,
$sendHeaders = true
) {
// Page title
$this->title = $title;
$this->show_learnpath = $show_learnpath;
$this->hide_global_chat = $hide_global_chat;
$this->load_plugins = $load_plugins;
$template_paths = array(
api_get_path(SYS_CODE_PATH).'template/overrides', // user defined templates
api_get_path(SYS_CODE_PATH).'template', //template folder
api_get_path(SYS_PLUGIN_PATH) // plugin folder
);
$cache_folder = api_get_path(SYS_ARCHIVE_PATH).'twig';
if (!is_dir($cache_folder)) {
mkdir($cache_folder, api_get_permissions_for_new_directories());
}
$loader = new Twig_Loader_Filesystem($template_paths);
//Setting Twig options depending on the server see http://twig.sensiolabs.org/doc/api.html#environment-options
if (api_get_setting('server_type') == 'test') {
$options = array(
//'cache' => api_get_path(SYS_ARCHIVE_PATH), //path to the cache folder
'autoescape' => false,
'debug' => true,
'auto_reload' => true,
'optimizations' => 0,
// turn on optimizations with -1
'strict_variables' => false,
//If set to false, Twig will silently ignore invalid variables
);
} else {
$options = array(
'cache' => $cache_folder,
//path to the cache folder
'autoescape' => false,
'debug' => false,
'auto_reload' => false,
'optimizations' => -1,
// turn on optimizations with -1
'strict_variables' => false
//If set to false, Twig will silently ignore invalid variables
);
}
$this->twig = new Twig_Environment($loader, $options);
$this->twig->addFilter('get_plugin_lang', new Twig_Filter_Function('get_plugin_lang'));
$this->twig->addFilter('get_lang', new Twig_Filter_Function('get_lang'));
$this->twig->addFilter('get_path', new Twig_Filter_Function('api_get_path'));
$this->twig->addFilter('get_setting', new Twig_Filter_Function('api_get_setting'));
$this->twig->addFilter('var_dump', new Twig_Filter_Function('var_dump'));
$this->twig->addFilter('return_message', new Twig_Filter_Function('Display::return_message_and_translate'));
$this->twig->addFilter('display_page_header', new Twig_Filter_Function('Display::page_header_and_translate'));
$this->twig->addFilter(
'display_page_subheader',
new Twig_Filter_Function('Display::page_subheader_and_translate')
);
$this->twig->addFilter('icon', new Twig_Filter_Function('Template::get_icon_path'));
$this->twig->addFilter('img', new Twig_Filter_Function('Template::get_image'));
$this->twig->addFilter('format_date', new Twig_Filter_Function('Template::format_date'));
$this->twig->addFilter('api_get_local_time', new Twig_Filter_Function('api_get_local_time'));
/*
$lexer = new Twig_Lexer($this->twig, array(
//'tag_comment' => array('{*', '*}'),
//'tag_comment' => array('{#', '#}'),
//'tag_block' => array('{', '}'),
//'tag_variable' => array('{$', '}'),
));
$this->twig->setLexer($lexer); */
//Setting system variables
$this->set_system_parameters();
//Setting user variables
$this->set_user_parameters();
//Setting course variables
$this->set_course_parameters();
//Setting administrator variables
$this->setAdministratorParams();
//header and footer are showed by default
$this->set_footer($show_footer);
$this->set_header($show_header);
$this->set_header_parameters($sendHeaders);
$this->set_footer_parameters();
$defaultStyle = api_get_configuration_value('default_template');
if (!empty($defaultStyle)) {
$this->templateFolder = $defaultStyle;
}
$this->assign('template', $this->templateFolder);
$this->assign('locale', api_get_language_isocode());
$this->assign('css_styles', $this->theme);
$this->assign('login_class', null);
$this->setLoginForm();
// Chamilo plugins
if ($this->show_header) {
if ($this->load_plugins) {
$this->plugin = new AppPlugin();
//1. Showing installed plugins in regions
$plugin_regions = $this->plugin->get_plugin_regions();
foreach ($plugin_regions as $region) {
$this->set_plugin_region($region);
}
//2. Loading the course plugin info
global $course_plugin;
if (isset($course_plugin) && !empty($course_plugin) && !empty($this->course_id)) {
//Load plugin get_langs
$this->plugin->load_plugin_lang_variables($course_plugin);
}
}
}
}
/**
* @param string $image
* @param int $size
*
* @return string
*/
public static function get_icon_path($image, $size = ICON_SIZE_SMALL)
{
return Display::return_icon($image, '', array(), $size, false, true);
}
/**
* @param string $image
* @param int $size
* @param string $name
* @return string
*/
public static function get_image($image, $size = ICON_SIZE_SMALL, $name)
{
return Display::return_icon($image, $name, array(), $size);
}
/**
* @param string $timestamp
* @param string $format
*
* @return string
*/
public static function format_date($timestamp, $format = null)
{
return api_format_date($timestamp, $format);
}
/**
* Return the item's url key:
*
* c_id=xx&id=xx
*
* @param object $item
* @return string
*/
public static function key($item)
{
$id = isset($item->id) ? $item->id : null;
$c_id = isset($item->c_id) ? $item->c_id : null;
$result = '';
if ($c_id) {
$result = "c_id=$c_id";
}
if ($id) {
if ($result) {
$result .= "&id=$id";
} else {
$result .= "&id=$id";
}
}
return $result;
}
/**
* @param string $helpInput
*/
public function setHelp($helpInput = null)
{
if (!empty($helpInput)) {
$help = $helpInput;
} else {
$help = $this->help;
}
$content = '';
if (api_get_setting('enable_help_link') == 'true') {
if (!empty($help)) {
$help = Security::remove_XSS($help);
$content = '<li class="help">';
$content .= Display::url(
Display::return_icon('help.large.png', get_lang('Help')),
api_get_path(WEB_CODE_PATH) . 'help/help.php?open=' . $help,
[
'class' => 'ajax',
'data-title' => get_lang('Help')
]
);
$content .= '</li>';
}
}
$this->assign('help_content', $content);
}
/**
* Use template system to parse the actions menu
* @todo finish it!
**/
public function set_actions($actions)
{
$action_string = '';
if (!empty($actions)) {
foreach ($actions as $action) {
$action_string .= $action;
}
}
$this->assign('actions', $actions);
}
/**
* Shortcut to display a 1 col layout (index.php)
* */
public function display_one_col_template()
{
$tpl = $this->get_template('layout/layout_1_col.tpl');
$this->display($tpl);
}
/**
* Shortcut to display a 2 col layout (userportal.php)
**/
public function display_two_col_template()
{
$tpl = $this->get_template('layout/layout_2_col.tpl');
$this->display($tpl);
}
/**
* Displays an empty template
*/
public function display_blank_template()
{
$tpl = $this->get_template('layout/blank.tpl');
$this->display($tpl);
}
/**
* Displays an empty template
*/
public function display_no_layout_template()
{
$tpl = $this->get_template('layout/no_layout.tpl');
$this->display($tpl);
}
/**
* Sets the footer visibility
* @param bool true if we show the footer
*/
public function set_footer($status)
{
$this->show_footer = $status;
$this->assign('show_footer', $status);
}
/**
* return true if toolbar has to be displayed for user
* @return bool
*/
public static function isToolBarDisplayedForUser()
{
//Toolbar
$show_admin_toolbar = api_get_setting('show_admin_toolbar');
$show_toolbar = false;
switch ($show_admin_toolbar) {
case 'do_not_show':
break;
case 'show_to_admin':
if (api_is_platform_admin()) {
$show_toolbar = true;
}
break;
case 'show_to_admin_and_teachers':
if (api_is_platform_admin() || api_is_allowed_to_edit()) {
$show_toolbar = true;
}
break;
case 'show_to_all':
$show_toolbar = true;
break;
}
return $show_toolbar;
}
/**
* Sets the header visibility
* @param bool true if we show the header
*/
public function set_header($status)
{
$this->show_header = $status;
$this->assign('show_header', $status);
$show_toolbar = 0;
if (self::isToolBarDisplayedForUser()) {
$show_toolbar = 1;
}
$this->assign('show_toolbar', $show_toolbar);
//Only if course is available
$show_course_shortcut = null;
$show_course_navigation_menu = null;
if (!empty($this->course_id) && $this->user_is_logged_in) {
if (api_get_setting('show_toolshortcuts') != 'false') {
//Course toolbar
$show_course_shortcut = CourseHome::show_navigation_tool_shortcuts();
}
if (api_get_setting('show_navigation_menu') != 'false') {
//Course toolbar
$show_course_navigation_menu = CourseHome::show_navigation_menu();
}
}
$this->assign('show_course_shortcut', $show_course_shortcut);
$this->assign('show_course_navigation_menu', $show_course_navigation_menu);
}
/**
* @param string $name
*
* @return string
*/
public function get_template($name)
{
return $this->templateFolder.'/'.$name;
}
/**
* Set course parameters
*/
private function set_course_parameters()
{
//Setting course id
$course = api_get_course_info();
if (empty($course)) {
$this->assign('course_is_set', false);
return;
}
$this->assign('course_is_set', true);
$this->course_id = $course['id'];
$_c = array(
'id' => $course['id'],
'code' => $course['code'],
'title' => $course['name'],
'visibility' => $course['visibility'],
'language' => $course['language'],
'directory' => $course['directory'],
'session_id' => api_get_session_id(),
'user_is_teacher' => api_is_course_admin(),
'student_view' => (!empty($_GET['isStudentView']) && $_GET['isStudentView'] == 'true'),
);
$this->assign('course_code', $course['code']);
$this->assign('_c', $_c);
}
/**
* Set user parameters
*/
private function set_user_parameters()
{
$user_info = array();
$user_info['logged'] = 0;
$this->user_is_logged_in = false;
if (api_user_is_login()) {
$user_info = api_get_user_info(api_get_user_id(), true);
$user_info['logged'] = 1;
$user_info['is_admin'] = 0;
if (api_is_platform_admin()) {
$user_info['is_admin'] = 1;
}
$user_info['messages_count'] = MessageManager::get_new_messages();
$this->user_is_logged_in = true;
}
// Setting the $_u array that could be use in any template
$this->assign('_u', $user_info);
}
/**
* Set system parameters
*/
private function set_system_parameters()
{
global $_configuration;
$this->theme = api_get_visual_theme();
//Setting app paths/URLs
$_p = array(
'web' => api_get_path(WEB_PATH),
'web_relative' => api_get_path(REL_PATH),
'web_course' => api_get_path(WEB_COURSE_PATH),
'web_main' => api_get_path(WEB_CODE_PATH),
'web_css' => api_get_path(WEB_CSS_PATH),
'web_css_theme' => api_get_path(WEB_CSS_PATH) . 'themes/' . $this->theme . '/',
'web_ajax' => api_get_path(WEB_AJAX_PATH),
'web_img' => api_get_path(WEB_IMG_PATH),
'web_plugin' => api_get_path(WEB_PLUGIN_PATH),
'web_lib' => api_get_path(WEB_LIBRARY_PATH),
'web_upload' => api_get_path(WEB_UPLOAD_PATH),
'web_self' => api_get_self(),
'web_query_vars' => api_htmlentities($_SERVER['QUERY_STRING']),
'web_self_query_vars' => api_htmlentities($_SERVER['REQUEST_URI']),
'web_cid_query' => api_get_cidreq(),
);
$this->assign('_p', $_p);
//Here we can add system parameters that can be use in any template
$_s = array(
'software_name' => $_configuration['software_name'],
'system_version' => $_configuration['system_version'],
'site_name' => api_get_setting('siteName'),
'institution' => api_get_setting('Institution'),
'date' => api_format_date('now', DATE_FORMAT_LONG),
'timezone' => _api_get_timezone(),
'gamification_mode' => api_get_setting('gamification_mode')
);
$this->assign('_s', $_s);
}
/**
* Set theme, include mainstream CSS files
* @return void
* @see setCssCustomFiles() for additional CSS sheets
*/
public function setCssFiles()
{
global $disable_js_and_css_files;
$css = array();
$this->theme = api_get_visual_theme();
if (!empty($this->preview_theme)) {
$this->theme = $this->preview_theme;
}
// Default CSS Bootstrap
$bowerCSSFiles = [
'bootstrap-daterangepicker/daterangepicker-bs3.css',
'fontawesome/css/font-awesome.min.css',
'jquery-ui/themes/smoothness/theme.css',
'jquery-ui/themes/smoothness/jquery-ui.min.css',
'mediaelement/build/mediaelementplayer.min.css',
'jqueryui-timepicker-addon/dist/jquery-ui-timepicker-addon.min.css',
'bootstrap/dist/css/bootstrap.min.css',
'jquery.scrollbar/jquery.scrollbar.css',
];
foreach ($bowerCSSFiles as $file) {
$css[] = api_get_path(WEB_PATH).'web/assets/'.$file;
}
$css[] = api_get_path(WEB_LIBRARY_PATH) . 'javascript/bootstrap-select/css/bootstrap-select.min.css';
$css[] = api_get_path(WEB_LIBRARY_PATH) . 'javascript/chosen/chosen.css';
$css[] = api_get_path(WEB_LIBRARY_PATH) . 'javascript/tag/style.css';
if (api_is_global_chat_enabled()) {
$css[] = api_get_path(WEB_LIBRARY_PATH) . 'javascript/chat/css/chat.css';
}
//THEME CSS STYLE
// $css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH).'responsive.css');
$css_file_to_string = null;
foreach ($css as $file) {
$css_file_to_string .= api_get_css($file);
}
if (!$disable_js_and_css_files) {
$this->assign('css_static_file_to_string', $css_file_to_string);
}
}
/**
* Prepare custom CSS to be added at the very end of the <head> section
* @return void
* @see setCssFiles() for the mainstream CSS files
*/
public function setCssCustomFiles()
{
global $disable_js_and_css_files;
// Base CSS
$css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH).'base.css');
if ($this->show_learnpath) {
$css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH).'scorm.css');
if (is_file(api_get_path(SYS_CSS_PATH).'themes/'.$this->theme.'/learnpath.css')) {
$css[] = api_get_path(WEB_CSS_PATH).'themes/'.$this->theme.'/learnpath.css';
}
}
$css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH).'themes/'.$this->theme.'/default.css');
$css_file_to_string = null;
foreach ($css as $file) {
$css_file_to_string .= api_get_css($file);
}
// @todo move this somewhere else. Special fix when using tablets in order to see the text near icons
if (SHOW_TEXT_NEAR_ICONS == true) {
//hack in order to fix the actions buttons
$css_file_to_string .= '<style>
.td_actions a {
float:left;
width:100%;
}
.forum_message_left a {
float:left;
width:100%;
}
</style>';
}
$navigator_info = api_get_navigator();
if ($navigator_info['name'] == 'Internet Explorer' && $navigator_info['version'] == '6') {
$css_file_to_string .= 'img, div { behavior: url('.api_get_path(WEB_LIBRARY_PATH).'javascript/iepngfix/iepngfix.htc) } '."\n";
}
if (!$disable_js_and_css_files) {
$this->assign('css_custom_file_to_string', $css_file_to_string);
$style_print = '';
if (is_readable(api_get_path(SYS_CSS_PATH).$this->theme.'/print.css')) {
$style_print = api_get_css(api_get_cdn_path(api_get_path(WEB_CSS_PATH) . $this->theme . '/print.css'),
'print');
}
$this->assign('css_style_print', $style_print);
}
// Logo
$logo = return_logo($this->theme);
$this->assign('logo', $logo);
$this->assign('show_media_element', 1);
}
/**
* Declare and define the template variable that will be used to load
* javascript libraries in the header.
*/
public function set_js_files()
{
global $disable_js_and_css_files, $htmlHeadXtra;
$isoCode = api_get_language_isocode();
$selectLink = 'bootstrap-select/js/i18n/defaults-' . $isoCode . '_' . strtoupper($isoCode) . '.min.js';
if ($isoCode == 'en') {
$selectLink = 'bootstrap-select/js/i18n/defaults-' . $isoCode . '_US.min.js';
}
// JS files
$js_files = array(
'chosen/chosen.jquery.min.js',
'bootstrap-select/js/bootstrap-select.min.js',
$selectLink
);
$viewBySession = api_get_setting('my_courses_view_by_session') === 'true';
if (api_is_global_chat_enabled() || $viewBySession) {
// Do not include the global chat in LP
if ($this->show_learnpath == false &&
$this->show_footer == true &&
$this->hide_global_chat == false
) {
$js_files[] = 'chat/js/chat.js';
}
}
if (api_get_setting('accessibility_font_resize') == 'true') {
$js_files[] = 'fontresize.js';
}
// Do not use minified version - generates errors (at least in the skills wheel)
$js_files[] = 'tag/jquery.fcbkcomplete.js';
$js_file_to_string = null;
$bowerJsFiles = [
'modernizr/modernizr.js',
'jquery/dist/jquery.min.js',
'bootstrap/dist/js/bootstrap.min.js',
'jquery-ui/jquery-ui.min.js',
'moment/min/moment-with-locales.min.js',
'ckeditor/ckeditor.js',
'bootstrap-daterangepicker/daterangepicker.js',
'jquery-timeago/jquery.timeago.js',
'mediaelement/build/mediaelement-and-player.min.js',
'jqueryui-timepicker-addon/dist/jquery-ui-timepicker-addon.min.js',
'imagemap-resizer/js/imageMapResizer.min.js',
'jquery.scrollbar/jquery.scrollbar.min.js'
];
if (api_get_setting('include_asciimathml_script') == 'true') {
$bowerJsFiles[] = 'MathJax/MathJax.js?config=AM_HTMLorMML';
}
if ($isoCode != 'en') {
$bowerJsFiles[] = 'jqueryui-timepicker-addon/dist/i18n/jquery-ui-timepicker-' . $isoCode . '.js';
$bowerJsFiles[] = 'jquery-ui/ui/minified/i18n/datepicker-' . $isoCode . '.min.js';
}
foreach ($bowerJsFiles as $file) {
$js_file_to_string .= '<script type="text/javascript" src="'.api_get_path(WEB_PATH).'web/assets/'.$file.'"></script>'."\n";
}
foreach ($js_files as $file) {
$js_file_to_string .= api_get_js($file);
}
// Loading email_editor js
if (!api_is_anonymous() && api_get_setting('allow_email_editor') == 'true') {
$js_file_to_string .= $this->fetch('default/mail_editor/email_link.js.tpl');
}
if (!$disable_js_and_css_files) {
$this->assign('js_file_to_string', $js_file_to_string);
//Adding jquery ui by default
$extra_headers = api_get_jquery_ui_js();
//$extra_headers = '';
if (isset($htmlHeadXtra) && $htmlHeadXtra) {
foreach ($htmlHeadXtra as & $this_html_head) {
$extra_headers .= $this_html_head."\n";
}
}
$this->assign('extra_headers', $extra_headers);
}
}
/**
* Special function to declare last-minute JS libraries which depend on
* other things to be declared first. In particular, it might be useful
* under IE9 with compatibility mode, which for some reason is getting
* upset when a variable is used in a function (even if not used yet)
* when this variable hasn't been defined yet.
*/
public function set_js_files_post()
{
global $disable_js_and_css_files, $htmlHeadXtra;
$js_files = array();
if (api_is_global_chat_enabled()) {
//Do not include the global chat in LP
if ($this->show_learnpath == false && $this->show_footer == true && $this->hide_global_chat == false) {
$js_files[] = 'chat/js/chat.js';
}
}
$js_file_to_string = null;
foreach ($js_files as $js_file) {
$js_file_to_string .= api_get_js($js_file);
}
if (!$disable_js_and_css_files) {
$this->assign('js_file_to_string_post', $js_file_to_string);
}
}
/**
* Set header parameters
* @param bool $sendHeaders send headers
*/
private function set_header_parameters($sendHeaders)
{
global $httpHeadXtra, $interbreadcrumb, $language_file, $_configuration, $this_section;
$_course = api_get_course_info();
$help = $this->help;
$nameTools = $this->title;
$navigation = return_navigation_array();
$this->menu_navigation = $navigation['menu_navigation'];
$this->assign('system_charset', api_get_system_encoding());
if (isset($httpHeadXtra) && $httpHeadXtra) {
foreach ($httpHeadXtra as & $thisHttpHead) {
header($thisHttpHead);
}
}
$this->assign('online_button', Display::return_icon('statusonline.png', null, null, ICON_SIZE_ATOM));
$this->assign('offline_button',Display::return_icon('statusoffline.png', null, null, ICON_SIZE_ATOM));
// Get language iso-code for this page - ignore errors
$this->assign('document_language', api_get_language_isocode());
$course_title = isset($_course['name']) ? $_course['name'] : null;
$title_list = array();
$title_list[] = api_get_setting('Institution');
$title_list[] = api_get_setting('siteName');
if (!empty($course_title)) {
$title_list[] = $course_title;
}
if ($nameTools != '') {
$title_list[] = $nameTools;
}
$title_string = '';
for ($i = 0; $i < count($title_list); $i++) {
$title_string .= $title_list[$i];
if (isset($title_list[$i + 1])) {
$item = trim($title_list[$i + 1]);
if (!empty($item)) {
$title_string .= ' - ';
}
}
}
$this->assign('title_string', $title_string);
//Setting the theme and CSS files
$css = $this->setCssFiles();
$this->set_js_files();
$this->setCssCustomFiles($css);
//$this->set_js_files_post();
$browser = api_browser_support('check_browser');
if ($browser[0] == 'Internet Explorer' && $browser[1] >= '11') {
$browser_head = '<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9" />';
$this->assign('browser_specific_head', $browser_head);
}
// Implementation of prefetch.
// See http://cdn.chamilo.org/main/img/online.png for details
$prefetch = '';
if (!empty($_configuration['cdn_enable'])) {
$prefetch .= '<meta http-equiv="x-dns-prefetch-control" content="on">';
foreach ($_configuration['cdn'] as $host => $exts) {
$prefetch .= '<link rel="dns-prefetch" href="'.$host.'">';
}
}
$this->assign('prefetch', $prefetch);
$this->assign('text_direction', api_get_text_direction());
$this->assign('section_name', 'section-'.$this_section);
//Defaul root chamilo favicon
$favico = '<link rel="shortcut icon" href="' . api_get_path(WEB_PATH) . 'favicon.ico" type="image/x-icon" />';
//Added to verify if in the current Chamilo Theme exist a favicon
$favicoThemeUrl = api_get_path(SYS_CSS_PATH) . 'themes/' . $this->theme . '/images/';
//If exist pick the current chamilo theme favicon
if (is_file($favicoThemeUrl . 'favicon.ico')) {
$favico = '<link rel="shortcut icon" href="' . api_get_path(WEB_CSS_PATH)
. 'themes/' . $this->theme . '/images/favicon.ico" type="image/x-icon" />';
}
if (api_is_multiple_url_enabled()) {
$access_url_id = api_get_current_access_url_id();
if ($access_url_id != -1) {
$url_info = api_get_access_url($access_url_id);
$url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $url_info['url']));
$clean_url = api_replace_dangerous_char($url);
$clean_url = str_replace('/', '-', $clean_url);
$clean_url .= '/';
$homep = api_get_path(REL_PATH).'home/'.$clean_url; //homep for Home Path
$icon_real_homep = api_get_path(SYS_APP_PATH).'home/'.$clean_url;
//we create the new dir for the new sites
if (is_file($icon_real_homep.'favicon.ico')) {
$favico = '<link rel="shortcut icon" href="'.$homep.'favicon.ico" type="image/x-icon" />';
}
}
}
$this->assign('favico', $favico);
$this->setHelp();
//@todo move this in the template
$bug_notification_link = '';
$iconBug = Display::return_icon('bug.png', get_lang('ReportABug'), null, ICON_SIZE_LARGE);
if (api_get_setting('show_link_bug_notification') == 'true' && $this->user_is_logged_in) {
$bug_notification_link = '<li class="report">
<a href="http://support.chamilo.org/projects/chamilo-18/wiki/How_to_report_bugs" target="_blank">
'. $iconBug . '
</a>
</li>';
}
$this->assign('bug_notification_link', $bug_notification_link);
$notification = return_notification_menu();
$this->assign('notification_menu', $notification);
$resize = '';
if (api_get_setting('accessibility_font_resize') == 'true') {
$resize .= '<div class="resize_font">';
$resize .= '<div class="btn-group">';
$resize .= '<a title="'.get_lang('DecreaseFontSize').'" href="#" class="decrease_font btn btn-default"><em class="fa fa-font"></em></a>';
$resize .= '<a title="'.get_lang('ResetFontSize').'" href="#" class="reset_font btn btn-default"><em class="fa fa-font"></em></a>';
$resize .= '<a title="'.get_lang('IncreaseFontSize').'" href="#" class="increase_font btn btn-default"><em class="fa fa-font"></em></a>';
$resize .= '</div>';
$resize .= '</div>';
}
$this->assign('accessibility', $resize);
// Preparing values for the menu
// Logout link
$hideLogout = api_get_setting('hide_logout_button');
if ($hideLogout === 'true') {
$this->assign('logout_link', null);
} else {
$this->assign('logout_link', api_get_path(WEB_PATH).'index.php?logout=logout&uid='.api_get_user_id());
}
//Profile link
if (api_get_setting('allow_social_tool') == 'true') {
$profile_url = api_get_path(WEB_CODE_PATH).'social/home.php';
$profile_link = Display::url(get_lang('Profile'), $profile_url);
} else {
$profile_url = api_get_path(WEB_CODE_PATH).'auth/profile.php';
$profile_link = Display::url(get_lang('Profile'), $profile_url);
}
$this->assign('profile_link', $profile_link);
$this->assign('profile_url', $profile_url);
//Message link
$message_link = null;
$message_url = null;
if (api_get_setting('allow_message_tool') == 'true') {
$message_url = api_get_path(WEB_CODE_PATH).'messages/inbox.php';
$message_link = '<a href="'.api_get_path(WEB_CODE_PATH).'messages/inbox.php">'.get_lang('Inbox').'</a>';
}
$this->assign('message_link', $message_link);
$this->assign('message_url', $message_url);
$institution = api_get_setting('Institution');
$portal_name = empty($institution) ? api_get_setting('siteName') : $institution;
$this->assign('portal_name', $portal_name);
//Menu
$menu = return_menu();
$this->assign('menu', $menu);
// Setting notifications
$count_unread_message = 0;
if (api_get_setting('allow_message_tool') == 'true') {
// get count unread message and total invitations
$count_unread_message = MessageManager::get_number_of_messages(true);
}
$total_invitations = 0;
if (api_get_setting('allow_social_tool') == 'true') {
$number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(
api_get_user_id()
);
$usergroup = new UserGroup();
$group_pending_invitations = $usergroup->get_groups_by_user(
api_get_user_id(),
GROUP_USER_PERMISSION_PENDING_INVITATION,
false
);
if (!empty($group_pending_invitations)) {
$group_pending_invitations = count($group_pending_invitations);
} else {
$group_pending_invitations = 0;
}
$total_invitations = intval($number_of_new_messages_of_friend) + $group_pending_invitations + intval($count_unread_message);
}
$total_invitations = (!empty($total_invitations) ? Display::badge($total_invitations) : null);
$this->assign('user_notifications', $total_invitations);
// Block Breadcrumb
$breadcrumb = return_breadcrumb($interbreadcrumb, $language_file, $nameTools);
$this->assign('breadcrumb', $breadcrumb);
//Extra content
$extra_header = null;
if (!api_is_platform_admin()) {
$extra_header = trim(api_get_setting('header_extra_content'));
}
$this->assign('header_extra_content', $extra_header);
if ($sendHeaders) {
header('Content-Type: text/html; charset='.api_get_system_encoding());
header(
'X-Powered-By: '.$_configuration['software_name'].' '.substr($_configuration['system_version'], 0, 1)
);
}
$socialMeta = '';
$metaTitle = api_get_setting('meta_title');
if (!empty($metaTitle)) {
$socialMeta .= '<meta name="twitter:card" content="summary" />' . "\n";
$socialMeta .= '<meta property="og:title" content="' . $metaTitle . '" />' . "\n";
$socialMeta .= '<meta property="og:url" content="' . api_get_path(WEB_PATH) . '" />' . "\n";
$metaDescription = api_get_setting('meta_description');
if (!empty($metaDescription)) {
$socialMeta .= '<meta property="og:description" content="' . $metaDescription . '" />' . "\n";
}
$metaSite = api_get_setting('meta_twitter_site');
if (!empty($metaSite)) {
$socialMeta .= '<meta name="twitter:site" content="' . $metaSite . '" />' . "\n";
$metaCreator = api_get_setting('meta_twitter_creator');
if (!empty($metaCreator)) {
$socialMeta .= '<meta name="twitter:creator" content="' . $metaCreator . '" />' . "\n";
}
}
$metaImage = api_get_setting('meta_image_path');
if (!empty($metaImage)) {
if (is_file(api_get_path(SYS_PATH) . $metaImage)) {
$path = api_get_path(WEB_PATH) . $metaImage;
$socialMeta .= '<meta property="og:image" content="' . $path . '" />' . "\n";
}
}
}