template.lib.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @author Julio Montoya <gugli100@gmail.com>
  5. * @todo better organization of the class, methods and variables
  6. *
  7. * */
  8. require_once api_get_path(LIBRARY_PATH).'banner.lib.php';
  9. require_once api_get_path(LIBRARY_PATH).'symfony/Twig/Autoloader.php';
  10. class Template
  11. {
  12. public $style = 'default'; //see the template folder
  13. public $preview_theme = null;
  14. public $theme; // the chamilo theme public_admin, chamilo, chamilo_red, etc
  15. public $title = null;
  16. public $show_header;
  17. public $show_footer;
  18. public $help;
  19. public $menu_navigation = array(); //Used in the userportal.lib.php function: return_navigation_course_links()
  20. public $show_learnpath = false; // This is a learnpath section or not?
  21. public $plugin = null;
  22. public $course_id = null;
  23. public $user_is_logged_in = false;
  24. public $twig = null;
  25. /* Loads chamilo plugins */
  26. public $load_plugins = false;
  27. public $params = array();
  28. public $force_plugin_load = false;
  29. /**
  30. * @param string $title
  31. * @param bool $show_header
  32. * @param bool $show_footer
  33. * @param bool $show_learnpath
  34. * @param bool $hide_global_chat
  35. * @param bool $load_plugins
  36. */
  37. public function __construct(
  38. $title = '',
  39. $show_header = true,
  40. $show_footer = true,
  41. $show_learnpath = false,
  42. $hide_global_chat = false,
  43. $load_plugins = true
  44. ) {
  45. // Page title
  46. $this->title = $title;
  47. $this->show_learnpath = $show_learnpath;
  48. $this->hide_global_chat = $hide_global_chat;
  49. $this->load_plugins = $load_plugins;
  50. //Twig settings
  51. Twig_Autoloader::register();
  52. $template_paths = array(
  53. api_get_path(SYS_CODE_PATH).'template', //template folder
  54. api_get_path(SYS_PLUGIN_PATH) //plugin folder
  55. );
  56. $cache_folder = api_get_path(SYS_ARCHIVE_PATH).'twig';
  57. if (!is_dir($cache_folder)) {
  58. mkdir($cache_folder, api_get_permissions_for_new_directories());
  59. }
  60. $loader = new Twig_Loader_Filesystem($template_paths);
  61. //Setting Twig options depending on the server see http://twig.sensiolabs.org/doc/api.html#environment-options
  62. if (api_get_setting('server_type') == 'test') {
  63. $options = array(
  64. //'cache' => api_get_path(SYS_ARCHIVE_PATH), //path to the cache folder
  65. 'autoescape' => false,
  66. 'debug' => true,
  67. 'auto_reload' => true,
  68. 'optimizations' => 0, // turn on optimizations with -1
  69. 'strict_variables' => false, //If set to false, Twig will silently ignore invalid variables
  70. );
  71. } else {
  72. $options = array(
  73. 'cache' => $cache_folder, //path to the cache folder
  74. 'autoescape' => false,
  75. 'debug' => false,
  76. 'auto_reload' => false,
  77. 'optimizations' => -1, // turn on optimizations with -1
  78. 'strict_variables' => false //If set to false, Twig will silently ignore invalid variables
  79. );
  80. }
  81. $this->twig = new Twig_Environment($loader, $options);
  82. $this->twig->addFilter('get_plugin_lang', new Twig_Filter_Function('get_plugin_lang'));
  83. $this->twig->addFilter('get_lang', new Twig_Filter_Function('get_lang'));
  84. $this->twig->addFilter('get_path', new Twig_Filter_Function('api_get_path'));
  85. $this->twig->addFilter('get_setting', new Twig_Filter_Function('api_get_setting'));
  86. $this->twig->addFilter('var_dump', new Twig_Filter_Function('var_dump'));
  87. $this->twig->addFilter('return_message', new Twig_Filter_Function('Display::return_message_and_translate'));
  88. $this->twig->addFilter('display_page_header', new Twig_Filter_Function('Display::page_header_and_translate'));
  89. $this->twig->addFilter(
  90. 'display_page_subheader',
  91. new Twig_Filter_Function('Display::page_subheader_and_translate')
  92. );
  93. $this->twig->addFilter('icon', new Twig_Filter_Function('Template::get_icon_path'));
  94. $this->twig->addFilter('format_date', new Twig_Filter_Function('Template::format_date'));
  95. $this->twig->addFilter('api_get_local_time', new Twig_Filter_Function('api_get_local_time'));
  96. /*
  97. $lexer = new Twig_Lexer($this->twig, array(
  98. //'tag_comment' => array('{*', '*}'),
  99. //'tag_comment' => array('{#', '#}'),
  100. //'tag_block' => array('{', '}'),
  101. //'tag_variable' => array('{$', '}'),
  102. ));
  103. $this->twig->setLexer($lexer); */
  104. //Setting system variables
  105. $this->set_system_parameters();
  106. //Setting user variables
  107. $this->set_user_parameters();
  108. //Setting course variables
  109. $this->set_course_parameters();
  110. //header and footer are showed by default
  111. $this->set_footer($show_footer);
  112. $this->set_header($show_header);
  113. $this->set_header_parameters();
  114. $this->set_footer_parameters();
  115. $this->assign('style', $this->style);
  116. $this->assign('css_style', $this->theme);
  117. $this->assign('template', $this->style);
  118. $this->assign('login_class', null);
  119. //Chamilo plugins
  120. if ($this->show_header) {
  121. if ($this->load_plugins) {
  122. $this->plugin = new AppPlugin();
  123. //1. Showing installed plugins in regions
  124. $plugin_regions = $this->plugin->get_plugin_regions();
  125. foreach ($plugin_regions as $region) {
  126. $this->set_plugin_region($region);
  127. }
  128. //2. Loading the course plugin info
  129. global $course_plugin;
  130. if (isset($course_plugin) && !empty($course_plugin) && !empty($this->course_id)) {
  131. //Load plugin get_langs
  132. $this->plugin->load_plugin_lang_variables($course_plugin);
  133. }
  134. }
  135. }
  136. }
  137. public static function get_icon_path($image, $size = ICON_SIZE_SMALL)
  138. {
  139. return Display:: return_icon($image, '', array(), $size, false, true);
  140. }
  141. public static function format_date($timestamp, $format = null)
  142. {
  143. return api_format_date($timestamp, $format);
  144. }
  145. /**
  146. * Return the item's url key:
  147. *
  148. * c_id=xx&id=xx
  149. *
  150. * @param object $item
  151. * @return string
  152. */
  153. public static function key($item)
  154. {
  155. $id = isset($item->id) ? $item->id : null;
  156. $c_id = isset($item->c_id) ? $item->c_id : null;
  157. $result = '';
  158. if ($c_id) {
  159. $result = "c_id=$c_id";
  160. }
  161. if ($id) {
  162. if ($result) {
  163. $result .= "&amp;id=$id";
  164. } else {
  165. $result .= "&amp;id=$id";
  166. }
  167. }
  168. return $result;
  169. }
  170. /**
  171. * @param string $helpInput
  172. */
  173. function set_help($helpInput = null)
  174. {
  175. if (!empty($helpInput)) {
  176. $help = $helpInput;
  177. } else {
  178. $help = $this->help;
  179. }
  180. $content = '';
  181. if (api_get_setting('enable_help_link') == 'true') {
  182. if (!empty($help)) {
  183. $help = Security::remove_XSS($help);
  184. $content = '<li class="help">';
  185. $content .= Display::url(
  186. Display::return_icon('help.large.png', get_lang('Help')),
  187. api_get_path(WEB_CODE_PATH).'help/help.php?open='.$help.'&height=400&width=600', array('class' => 'ajax'));
  188. $content .= '</li>';
  189. }
  190. }
  191. $this->assign('help_content', $content);
  192. }
  193. /*
  194. * Use template system to parse the actions menu
  195. * @todo finish it!
  196. * */
  197. function set_actions($actions)
  198. {
  199. $action_string = '';
  200. if (!empty($actions)) {
  201. foreach ($actions as $action) {
  202. $action_string .= $action;
  203. }
  204. }
  205. $this->assign('actions', $actions);
  206. }
  207. /**
  208. * Shortcut to display a 1 col layout (index.php)
  209. * */
  210. function display_one_col_template()
  211. {
  212. $tpl = $this->get_template('layout/layout_1_col.tpl');
  213. $this->display($tpl);
  214. }
  215. /**
  216. * Shortcut to display a 2 col layout (userportal.php)
  217. * */
  218. function display_two_col_template()
  219. {
  220. $tpl = $this->get_template('layout/layout_2_col.tpl');
  221. $this->display($tpl);
  222. }
  223. /**
  224. * Displays an empty template
  225. */
  226. function display_blank_template()
  227. {
  228. $tpl = $this->get_template('layout/blank.tpl');
  229. $this->display($tpl);
  230. }
  231. /**
  232. * Displays an empty template
  233. */
  234. function display_no_layout_template()
  235. {
  236. $tpl = $this->get_template('layout/no_layout.tpl');
  237. $this->display($tpl);
  238. }
  239. /**
  240. * Sets the footer visibility
  241. * @param bool true if we show the footer
  242. */
  243. function set_footer($status)
  244. {
  245. $this->show_footer = $status;
  246. $this->assign('show_footer', $status);
  247. }
  248. /**
  249. * Sets the header visibility
  250. * @param bool true if we show the header
  251. */
  252. function set_header($status)
  253. {
  254. $this->show_header = $status;
  255. $this->assign('show_header', $status);
  256. //Toolbar
  257. $show_admin_toolbar = api_get_setting('show_admin_toolbar');
  258. $show_toolbar = 0;
  259. switch ($show_admin_toolbar) {
  260. case 'do_not_show':
  261. break;
  262. case 'show_to_admin':
  263. if (api_is_platform_admin()) {
  264. $show_toolbar = 1;
  265. }
  266. break;
  267. case 'show_to_admin_and_teachers':
  268. if (api_is_platform_admin() || api_is_allowed_to_edit()) {
  269. $show_toolbar = 1;
  270. }
  271. break;
  272. case 'show_to_all':
  273. $show_toolbar = 1;
  274. break;
  275. }
  276. $this->assign('show_toolbar', $show_toolbar);
  277. //Only if course is available
  278. $show_course_shortcut = null;
  279. $show_course_navigation_menu = null;
  280. if (!empty($this->course_id) && $this->user_is_logged_in) {
  281. if (api_get_setting('show_toolshortcuts') != 'false') {
  282. //Course toolbar
  283. $show_course_shortcut = CourseHome::show_navigation_tool_shortcuts();
  284. }
  285. if (api_get_setting('show_navigation_menu') != 'false') {
  286. //Course toolbar
  287. $show_course_navigation_menu = CourseHome::show_navigation_menu();
  288. }
  289. }
  290. $this->assign('show_course_shortcut', $show_course_shortcut);
  291. $this->assign('show_course_navigation_menu', $show_course_navigation_menu);
  292. }
  293. function get_template($name)
  294. {
  295. return $this->style.'/'.$name;
  296. }
  297. /** Set course parameters */
  298. private function set_course_parameters()
  299. {
  300. //Setting course id
  301. $course = api_get_course_info();
  302. if (empty($course)) {
  303. $this->assign('course_is_set', false);
  304. return;
  305. }
  306. $this->assign('course_is_set', true);
  307. $this->course_id = $course['id'];
  308. $_c = array(
  309. 'id' => $course['id'],
  310. 'code' => $course['code'],
  311. 'title' => $course['name'],
  312. 'visibility' => $course['visibility'],
  313. 'language' => $course['language'],
  314. 'directory' => $course['directory'],
  315. 'session_id' => api_get_session_id(),
  316. 'user_is_teacher' => api_is_course_admin(),
  317. 'student_view' => (!empty($_GET['isStudentView']) && $_GET['isStudentView'] == 'true'),
  318. );
  319. $this->assign('course_code', $course['code']);
  320. $this->assign('_c', $_c);
  321. }
  322. /** Set user parameters */
  323. private function set_user_parameters()
  324. {
  325. $user_info = array();
  326. $user_info['logged'] = 0;
  327. $this->user_is_logged_in = false;
  328. if (api_user_is_login()) {
  329. $user_info = api_get_user_info(api_get_user_id());
  330. $user_info['logged'] = 1;
  331. $user_info['is_admin'] = 0;
  332. if (api_is_platform_admin()) {
  333. $user_info['is_admin'] = 1;
  334. }
  335. $user_info['messages_count'] = MessageManager::get_new_messages();
  336. $this->user_is_logged_in = true;
  337. }
  338. //Setting the $_u array that could be use in any template
  339. $this->assign('_u', $user_info);
  340. }
  341. /** Set system parameters */
  342. private function set_system_parameters()
  343. {
  344. global $_configuration;
  345. //Setting app paths/URLs
  346. $_p = array(
  347. 'web' => api_get_path(WEB_PATH),
  348. 'web_course' => api_get_path(WEB_COURSE_PATH),
  349. 'web_main' => api_get_path(WEB_CODE_PATH),
  350. 'web_css' => api_get_path(WEB_CSS_PATH),
  351. 'web_ajax' => api_get_path(WEB_AJAX_PATH),
  352. 'web_img' => api_get_path(WEB_IMG_PATH),
  353. 'web_plugin' => api_get_path(WEB_PLUGIN_PATH),
  354. 'web_lib' => api_get_path(WEB_LIBRARY_PATH),
  355. 'web_self' => api_get_self(),
  356. 'web_query_vars' => api_htmlentities($_SERVER['QUERY_STRING']),
  357. 'web_self_query_vars' => api_htmlentities($_SERVER['REQUEST_URI']),
  358. 'web_cid_query' => api_get_cidreq(),
  359. );
  360. $this->assign('_p', $_p);
  361. //Here we can add system parameters that can be use in any template
  362. $_s = array(
  363. 'software_name' => $_configuration['software_name'],
  364. 'system_version' => $_configuration['system_version'],
  365. 'site_name' => api_get_setting('siteName'),
  366. 'institution' => api_get_setting('Institution')
  367. );
  368. $this->assign('_s', $_s);
  369. }
  370. /**
  371. * Set theme, include CSS files */
  372. function set_css_files()
  373. {
  374. global $disable_js_and_css_files;
  375. $css = array();
  376. //$platform_theme = api_get_setting('stylesheets');
  377. $this->theme = api_get_visual_theme();
  378. if (!empty($this->preview_theme)) {
  379. $this->theme = $this->preview_theme;
  380. }
  381. //Base CSS
  382. $css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH).'base.css');
  383. //Default CSS responsive design
  384. $css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH).'bootstrap-responsive.css');
  385. //Extra CSS files
  386. $css[] = api_get_path(WEB_LIBRARY_PATH).'javascript/thickbox.css';
  387. $css[] = api_get_path(WEB_LIBRARY_PATH).'javascript/chosen/chosen.css';
  388. if (api_is_global_chat_enabled()) {
  389. $css[] = api_get_path(WEB_LIBRARY_PATH).'javascript/chat/css/chat.css';
  390. }
  391. $css[] = api_get_path(WEB_CSS_PATH).'font_awesome/css/font-awesome.css';
  392. $css[] = api_get_path(WEB_LIBRARY_PATH).'javascript/mediaelement/mediaelementplayer.css';
  393. //THEME CSS STYLE
  394. $css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH).'responsive.css');
  395. $css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH).$this->theme.'/default.css');
  396. if ($this->show_learnpath) {
  397. $css[] = api_get_path(WEB_CSS_PATH).$this->theme.'/learnpath.css';
  398. // if we have a SCORM file in theme, don't use default_scorm.css file
  399. if (is_file(api_get_path(SYS_CSS_PATH).$this->theme.'/scorm.css')) {
  400. $css[] = api_get_path(WEB_CSS_PATH).$this->theme.'/scorm.css';
  401. } else {
  402. $css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH).'default_scorm.css');
  403. }
  404. }
  405. $css_file_to_string = null;
  406. foreach ($css as $file) {
  407. $css_file_to_string .= api_get_css($file);
  408. }
  409. // @todo move this somewhere else. Special fix when using tablets in order to see the text near icons
  410. if (SHOW_TEXT_NEAR_ICONS == true) {
  411. //hack in order to fix the actions buttons
  412. $css_file_to_string .= '<style>
  413. .td_actions a {
  414. float:left;
  415. width:100%;
  416. }
  417. .forum_message_left a {
  418. float:left;
  419. width:100%;
  420. }
  421. </style>';
  422. }
  423. $navigator_info = api_get_navigator();
  424. if ($navigator_info['name'] == 'Internet Explorer' && $navigator_info['version'] == '6') {
  425. $css_file_to_string .= 'img, div { behavior: url('.api_get_path(WEB_LIBRARY_PATH).'javascript/iepngfix/iepngfix.htc) } '."\n";
  426. }
  427. if (!$disable_js_and_css_files) {
  428. $this->assign('css_file_to_string', $css_file_to_string);
  429. $style_print = api_get_css(api_get_cdn_path(api_get_path(WEB_CSS_PATH).$this->theme.'/print.css'), 'print');
  430. $this->assign('css_style_print', $style_print);
  431. }
  432. // Logo
  433. $logo = return_logo($this->theme);
  434. $this->assign('logo', $logo);
  435. }
  436. /**
  437. * Declare and define the template variable that will be used to load
  438. * javascript libraries in the header.
  439. */
  440. function set_js_files()
  441. {
  442. global $disable_js_and_css_files, $htmlHeadXtra;
  443. //JS files
  444. $js_files = array(
  445. 'modernizr.js',
  446. 'jquery.min.js',
  447. 'chosen/chosen.jquery.min.js',
  448. 'thickbox.js',
  449. 'bootstrap/bootstrap.js',
  450. 'mediaelement/mediaelement-and-player.min.js'
  451. );
  452. if (api_is_global_chat_enabled()) {
  453. //Do not include the global chat in LP
  454. if ($this->show_learnpath == false && $this->show_footer == true && $this->hide_global_chat == false) {
  455. $js_files[] = 'chat/js/chat.js';
  456. }
  457. }
  458. if (api_get_setting('accessibility_font_resize') == 'true') {
  459. $js_files[] = 'fontresize.js';
  460. }
  461. if (api_get_setting('include_asciimathml_script') == 'true') {
  462. $js_files[] = 'asciimath/ASCIIMathML.js';
  463. }
  464. $js_file_to_string = null;
  465. foreach ($js_files as $js_file) {
  466. $js_file_to_string .= api_get_js($js_file);
  467. }
  468. //Loading email_editor js
  469. if (!api_is_anonymous() && api_get_setting('allow_email_editor') == 'true') {
  470. $js_file_to_string .= $this->fetch('default/mail_editor/email_link.js.tpl');
  471. }
  472. if (!$disable_js_and_css_files) {
  473. $this->assign('js_file_to_string', $js_file_to_string);
  474. //Adding jquery ui by default
  475. $extra_headers = api_get_jquery_ui_js();
  476. //$extra_headers = '';
  477. if (isset($htmlHeadXtra) && $htmlHeadXtra) {
  478. foreach ($htmlHeadXtra as & $this_html_head) {
  479. $extra_headers .= $this_html_head."\n";
  480. }
  481. }
  482. $this->assign('extra_headers', $extra_headers);
  483. }
  484. }
  485. /**
  486. * Special function to declare last-minute JS libraries which depend on
  487. * other things to be declared first. In particular, it might be useful
  488. * under IE9 with compatibility mode, which for some reason is getting
  489. * upset when a variable is used in a function (even if not used yet)
  490. * when this variable hasn't been defined yet.
  491. */
  492. function set_js_files_post()
  493. {
  494. global $disable_js_and_css_files, $htmlHeadXtra;
  495. $js_files = array();
  496. if (api_is_global_chat_enabled()) {
  497. //Do not include the global chat in LP
  498. if ($this->show_learnpath == false && $this->show_footer == true && $this->hide_global_chat == false) {
  499. $js_files[] = 'chat/js/chat.js';
  500. }
  501. }
  502. $js_file_to_string = null;
  503. foreach ($js_files as $js_file) {
  504. $js_file_to_string .= api_get_js($js_file);
  505. }
  506. if (!$disable_js_and_css_files) {
  507. $this->assign('js_file_to_string_post', $js_file_to_string);
  508. }
  509. }
  510. /**
  511. * Set header parameters
  512. */
  513. private function set_header_parameters()
  514. {
  515. global $httpHeadXtra, $_course, $interbreadcrumb, $language_file, $noPHP_SELF, $_configuration, $this_section;
  516. $help = $this->help;
  517. $nameTools = $this->title;
  518. $navigation = return_navigation_array();
  519. $this->menu_navigation = $navigation['menu_navigation'];
  520. $this->assign('system_charset', api_get_system_encoding());
  521. if (isset($httpHeadXtra) && $httpHeadXtra) {
  522. foreach ($httpHeadXtra as & $thisHttpHead) {
  523. header($thisHttpHead);
  524. }
  525. }
  526. $this->assign('online_button', Display::return_icon('online.png'));
  527. $this->assign('offline_button',Display::return_icon('offline.png'));
  528. // Get language iso-code for this page - ignore errors
  529. $this->assign('document_language', api_get_language_isocode());
  530. $course_title = isset($_course['name']) ? $_course['name'] : null;
  531. $title_list = array();
  532. $title_list[] = api_get_setting('Institution');
  533. $title_list[] = api_get_setting('siteName');
  534. if (!empty($course_title)) {
  535. $title_list[] = $course_title;
  536. }
  537. if ($nameTools != '') {
  538. $title_list[] = $nameTools;
  539. }
  540. $title_string = '';
  541. for ($i = 0; $i < count($title_list); $i++) {
  542. $title_string .= $title_list[$i];
  543. if (isset($title_list[$i + 1])) {
  544. $item = trim($title_list[$i + 1]);
  545. if (!empty($item)) {
  546. $title_string .= ' - ';
  547. }
  548. }
  549. }
  550. $this->assign('title_string', $title_string);
  551. //Setting the theme and CSS files
  552. $this->set_css_files();
  553. $this->set_js_files();
  554. //$this->set_js_files_post();
  555. $browser = api_browser_support('check_browser');
  556. if ($browser[0] == 'Internet Explorer' && $browser[1] >= '11') {
  557. $browser_head = '<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9" />';
  558. $this->assign('browser_specific_head', $browser_head);
  559. }
  560. // Implementation of prefetch.
  561. // See http://cdn.chamilo.org/main/img/online.png for details
  562. $prefetch = '';
  563. if (!empty($_configuration['cdn_enable'])) {
  564. $prefetch .= '<meta http-equiv="x-dns-prefetch-control" content="on">';
  565. foreach ($_configuration['cdn'] as $host => $exts) {
  566. $prefetch .= '<link rel="dns-prefetch" href="'.$host.'">';
  567. }
  568. }
  569. $this->assign('prefetch', $prefetch);
  570. $this->assign('text_direction', api_get_text_direction());
  571. $this->assign('section_name', 'section-'.$this_section);
  572. $favico = '<link rel="shortcut icon" href="'.api_get_path(WEB_PATH).'favicon.ico" type="image/x-icon" />';
  573. if (isset($_configuration['multiple_access_urls']) && $_configuration['multiple_access_urls']) {
  574. $access_url_id = api_get_current_access_url_id();
  575. if ($access_url_id != -1) {
  576. $url_info = api_get_access_url($access_url_id);
  577. $url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $url_info['url']));
  578. $clean_url = replace_dangerous_char($url);
  579. $clean_url = str_replace('/', '-', $clean_url);
  580. $clean_url .= '/';
  581. $homep = api_get_path(REL_PATH).'home/'.$clean_url; //homep for Home Path
  582. $icon_real_homep = api_get_path(SYS_PATH).'home/'.$clean_url;
  583. //we create the new dir for the new sites
  584. if (is_file($icon_real_homep.'favicon.ico')) {
  585. $favico = '<link rel="shortcut icon" href="'.$homep.'favicon.ico" type="image/x-icon" />';
  586. }
  587. }
  588. }
  589. $this->assign('favico', $favico);
  590. $this->set_help();
  591. //@todo move this in the template
  592. $bug_notification_link = '';
  593. if (api_get_setting('show_link_bug_notification') == 'true' && $this->user_is_logged_in) {
  594. $bug_notification_link = '<li class="report">
  595. <a href="http://support.chamilo.org/projects/chamilo-18/wiki/How_to_report_bugs" target="_blank">
  596. <img src="'.api_get_path(WEB_IMG_PATH).'bug.large.png" style="vertical-align: middle;" alt="'.get_lang('ReportABug').'" title="'.get_lang(
  597. 'ReportABug'
  598. ).'"/></a>
  599. </li>';
  600. }
  601. $this->assign('bug_notification_link', $bug_notification_link);
  602. $notification = return_notification_menu();
  603. $this->assign('notification_menu', $notification);
  604. //Preparing values for the menu
  605. //Logout link
  606. $this->assign('logout_link', api_get_path(WEB_PATH).'index.php?logout=logout&&uid='.api_get_user_id());
  607. //Profile link
  608. if (api_get_setting('allow_social_tool') == 'true') {
  609. $profile_url = api_get_path(WEB_CODE_PATH).'social/home.php';
  610. $profile_link = Display::url(get_lang('Profile'), $profile_url);
  611. } else {
  612. $profile_url = api_get_path(WEB_CODE_PATH).'auth/profile.php';
  613. $profile_link = Display::url(get_lang('Profile'), $profile_url);
  614. }
  615. $this->assign('profile_link', $profile_link);
  616. $this->assign('profile_url', $profile_url);
  617. //Message link
  618. $message_link = null;
  619. $message_url = null;
  620. if (api_get_setting('allow_message_tool') == 'true') {
  621. $message_url = api_get_path(WEB_CODE_PATH).'messages/inbox.php';
  622. $message_link = '<a href="'.api_get_path(WEB_CODE_PATH).'messages/inbox.php">'.get_lang('Inbox').'</a>';
  623. }
  624. $this->assign('message_link', $message_link);
  625. $this->assign('message_url', $message_url);
  626. $institution = api_get_setting('Institution');
  627. $portal_name = empty($institution) ? api_get_setting('siteName') : $institution;
  628. $this->assign('portal_name', $portal_name);
  629. //Menu
  630. $menu = return_menu();
  631. $this->assign('menu', $menu);
  632. //Setting notifications
  633. $count_unread_message = 0;
  634. if (api_get_setting('allow_message_tool') == 'true') {
  635. // get count unread message and total invitations
  636. $count_unread_message = MessageManager::get_number_of_messages(true);
  637. }
  638. $total_invitations = 0;
  639. if (api_get_setting('allow_social_tool') == 'true') {
  640. $number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(
  641. api_get_user_id()
  642. );
  643. $group_pending_invitations = GroupPortalManager::get_groups_by_user(
  644. api_get_user_id(),
  645. GROUP_USER_PERMISSION_PENDING_INVITATION,
  646. false
  647. );
  648. $group_pending_invitations = 0;
  649. if (!empty($group_pending_invitations)) {
  650. $group_pending_invitations = count($group_pending_invitations);
  651. }
  652. $total_invitations = intval($number_of_new_messages_of_friend) + $group_pending_invitations + intval(
  653. $count_unread_message
  654. );
  655. }
  656. $total_invitations = (!empty($total_invitations) ? Display::badge($total_invitations) : null);
  657. $this->assign('user_notifications', $total_invitations);
  658. //Breadcrumb
  659. $breadcrumb = return_breadcrumb($interbreadcrumb, $language_file, $nameTools);
  660. $this->assign('breadcrumb', $breadcrumb);
  661. //Extra content
  662. $extra_header = null;
  663. if (!api_is_platform_admin()) {
  664. $extra_header = trim(api_get_setting('header_extra_content'));
  665. }
  666. $this->assign('header_extra_content', $extra_header);
  667. //if ($this->show_header == 1) {
  668. header('Content-Type: text/html; charset='.api_get_system_encoding());
  669. header(
  670. 'X-Powered-By: '.$_configuration['software_name'].' '.substr($_configuration['system_version'], 0, 1)
  671. );
  672. //}
  673. }
  674. /**
  675. * Set footer parameteres
  676. */
  677. private function set_footer_parameters()
  678. {
  679. global $_configuration;
  680. //Show admin data
  681. //$this->assign('show_administrator_data', api_get_setting('show_administrator_data'));
  682. if (api_get_setting('show_administrator_data') == 'true') {
  683. //Administrator name
  684. $administrator_data = get_lang('Manager').' : '.Display::encrypted_mailto_link(
  685. api_get_setting('emailAdministrator'),
  686. api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'))
  687. );
  688. $this->assign('administrator_name', $administrator_data);
  689. }
  690. //Loading footer extra content
  691. if (!api_is_platform_admin()) {
  692. $extra_footer = trim(api_get_setting('footer_extra_content'));
  693. if (!empty($extra_footer)) {
  694. $this->assign('footer_extra_content', $extra_footer);
  695. }
  696. }
  697. //Tutor name
  698. if (api_get_setting('show_tutor_data') == 'true') {
  699. // Course manager
  700. $id_course = api_get_course_id();
  701. $id_session = api_get_session_id();
  702. if (isset($id_course) && $id_course != -1) {
  703. $tutor_data = '';
  704. if ($id_session != 0) {
  705. $coachs_email = CourseManager::get_email_of_tutor_to_session($id_session, $id_course);
  706. $email_link = array();
  707. foreach ($coachs_email as $coach) {
  708. $email_link[] = Display::encrypted_mailto_link($coach['email'], $coach['complete_name']);
  709. }
  710. if (count($coachs_email) > 1) {
  711. $tutor_data .= get_lang('Coachs').' : ';
  712. $tutor_data .= array_to_string($email_link, CourseManager::USER_SEPARATOR);
  713. } elseif (count($coachs_email) == 1) {
  714. $tutor_data .= get_lang('Coach').' : ';
  715. $tutor_data .= array_to_string($email_link, CourseManager::USER_SEPARATOR);
  716. } elseif (count($coachs_email) == 0) {
  717. $tutor_data .= '';
  718. }
  719. }
  720. $this->assign('session_teachers', $tutor_data);
  721. }
  722. }
  723. if (api_get_setting('show_teacher_data') == 'true') {
  724. // course manager
  725. $id_course = api_get_course_id();
  726. if (isset($id_course) && $id_course != -1) {
  727. $teacher_data = '';
  728. $mail = CourseManager::get_emails_of_tutors_to_course($id_course);
  729. if (!empty($mail)) {
  730. $teachers_parsed = array();
  731. foreach ($mail as $value) {
  732. foreach ($value as $email => $name) {
  733. $teachers_parsed[] = Display::encrypted_mailto_link($email, $name);
  734. }
  735. }
  736. $label = get_lang('Teacher');
  737. if (count($mail) > 1) {
  738. $label = get_lang('Teachers');
  739. }
  740. $teacher_data .= $label.' : '.array_to_string($teachers_parsed, CourseManager::USER_SEPARATOR);
  741. }
  742. $this->assign('teachers', $teacher_data);
  743. }
  744. }
  745. /* $stats = '';
  746. $this->assign('execution_stats', $stats); */
  747. }
  748. function show_header_template()
  749. {
  750. $tpl = $this->get_template('layout/show_header.tpl');
  751. $this->display($tpl);
  752. }
  753. function show_footer_template()
  754. {
  755. $tpl = $this->get_template('layout/show_footer.tpl');
  756. $this->display($tpl);
  757. }
  758. /* Sets the plugin content in a template variable */
  759. function set_plugin_region($plugin_region)
  760. {
  761. if (!empty($plugin_region)) {
  762. $region_content = $this->plugin->load_region($plugin_region, $this, $this->force_plugin_load);
  763. if (!empty($region_content)) {
  764. $this->assign('plugin_'.$plugin_region, $region_content);
  765. } else {
  766. $this->assign('plugin_'.$plugin_region, null);
  767. }
  768. }
  769. return null;
  770. }
  771. public function fetch($template = null)
  772. {
  773. $template = $this->twig->loadTemplate($template);
  774. return $template->render($this->params);
  775. }
  776. public function assign($tpl_var, $value = null)
  777. {
  778. $this->params[$tpl_var] = $value;
  779. }
  780. public function display($template)
  781. {
  782. echo $this->twig->render($template, $this->params);
  783. }
  784. /**
  785. * Adds a body class for login pages
  786. */
  787. public function setLoginBodyClass()
  788. {
  789. $this->assign('login_class', 'section-login');
  790. }
  791. }