Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Template often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Template, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 35 | class Template |
||
| 36 | { |
||
| 37 | /** |
||
| 38 | * The Template folder name see main/template |
||
| 39 | * @var string |
||
| 40 | */ |
||
| 41 | public $templateFolder = 'default'; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * The theme that will be used: chamilo, public_admin, chamilo_red, etc |
||
| 45 | * This variable is set from the database |
||
| 46 | * @var string |
||
| 47 | */ |
||
| 48 | public $theme = ''; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @var string |
||
| 52 | */ |
||
| 53 | public $preview_theme = ''; |
||
| 54 | public $title = null; |
||
| 55 | public $show_header; |
||
| 56 | public $show_footer; |
||
| 57 | public $help; |
||
| 58 | public $menu_navigation = array(); //Used in the userportal.lib.php function: return_navigation_course_links() |
||
| 59 | public $show_learnpath = false; // This is a learnpath section or not? |
||
| 60 | public $plugin = null; |
||
| 61 | public $course_id = null; |
||
| 62 | public $user_is_logged_in = false; |
||
| 63 | public $twig = null; |
||
| 64 | |||
| 65 | /* Loads chamilo plugins */ |
||
| 66 | public $load_plugins = false; |
||
| 67 | public static $params = array(); |
||
| 68 | public $force_plugin_load = false; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * |
||
| 72 | * @param string $title |
||
| 73 | * @param bool $show_header |
||
| 74 | * @param bool $show_footer |
||
| 75 | * @param bool $show_learnpath |
||
| 76 | * @param bool $hide_global_chat |
||
| 77 | * @param bool $load_plugins |
||
| 78 | * @param bool $sendHeaders send http headers or not |
||
| 79 | */ |
||
| 80 | public function __construct( |
||
| 240 | |||
| 241 | /** |
||
| 242 | * @param string $image |
||
| 243 | * @param int $size |
||
| 244 | * |
||
| 245 | * @return string |
||
| 246 | */ |
||
| 247 | public static function get_icon_path($image, $size = ICON_SIZE_SMALL) |
||
| 251 | |||
| 252 | /** |
||
| 253 | * @param string $image |
||
| 254 | * @param int $size |
||
| 255 | * @param string $name |
||
| 256 | * @return string |
||
| 257 | */ |
||
| 258 | public static function get_image($image, $size = ICON_SIZE_SMALL, $name) |
||
| 262 | |||
| 263 | /** |
||
| 264 | * @param string $timestamp |
||
| 265 | * @param string $format |
||
| 266 | * |
||
| 267 | * @return string |
||
| 268 | */ |
||
| 269 | public static function format_date($timestamp, $format = null) |
||
| 273 | |||
| 274 | /** |
||
| 275 | * Return the item's url key: |
||
| 276 | * |
||
| 277 | * c_id=xx&id=xx |
||
| 278 | * |
||
| 279 | * @param object $item |
||
| 280 | * @return string |
||
| 281 | */ |
||
| 282 | public static function key($item) |
||
| 299 | |||
| 300 | /** |
||
| 301 | * @param string $helpInput |
||
| 302 | */ |
||
| 303 | public function setHelp($helpInput = null) |
||
| 329 | |||
| 330 | /** |
||
| 331 | * Use template system to parse the actions menu |
||
| 332 | * @todo finish it! |
||
| 333 | **/ |
||
| 334 | public function set_actions($actions) |
||
| 344 | |||
| 345 | /** |
||
| 346 | * Render the template |
||
| 347 | * @param string $template The template path |
||
| 348 | * @param boolean $clearFlashMessages Clear the $_SESSION variables for flash messages |
||
| 349 | */ |
||
| 350 | public function display($template, $clearFlashMessages = true) |
||
| 355 | |||
| 356 | /** |
||
| 357 | * Shortcut to display a 1 col layout (index.php) |
||
| 358 | * */ |
||
| 359 | public function display_one_col_template() |
||
| 363 | |||
| 364 | /** |
||
| 365 | * Shortcut to display a 2 col layout (userportal.php) |
||
| 366 | **/ |
||
| 367 | public function display_two_col_template() |
||
| 371 | |||
| 372 | /** |
||
| 373 | * Displays an empty template |
||
| 374 | */ |
||
| 375 | public function display_blank_template() |
||
| 379 | |||
| 380 | /** |
||
| 381 | * Displays an empty template |
||
| 382 | */ |
||
| 383 | public function display_no_layout_template() |
||
| 387 | |||
| 388 | /** |
||
| 389 | * Sets the footer visibility |
||
| 390 | * @param bool true if we show the footer |
||
| 391 | */ |
||
| 392 | public function set_footer($status) |
||
| 397 | |||
| 398 | /** |
||
| 399 | * return true if toolbar has to be displayed for user |
||
| 400 | * @return bool |
||
| 401 | */ |
||
| 402 | public static function isToolBarDisplayedForUser() |
||
| 427 | |||
| 428 | /** |
||
| 429 | * Sets the header visibility |
||
| 430 | * @param bool true if we show the header |
||
| 431 | */ |
||
| 432 | public function set_header($status) |
||
| 433 | { |
||
| 434 | $this->show_header = $status; |
||
| 435 | $this->assign('show_header', $status); |
||
| 436 | |||
| 437 | $show_toolbar = 0; |
||
| 438 | |||
| 439 | if (self::isToolBarDisplayedForUser()) { |
||
| 440 | $show_toolbar = 1; |
||
| 441 | } |
||
| 442 | |||
| 443 | $this->assign('show_toolbar', $show_toolbar); |
||
| 444 | |||
| 445 | //Only if course is available |
||
| 446 | $show_course_shortcut = null; |
||
| 447 | $show_course_navigation_menu = null; |
||
| 448 | |||
| 449 | if (!empty($this->course_id) && $this->user_is_logged_in) { |
||
| 450 | |||
| 451 | if (api_get_setting('show_toolshortcuts') != 'false') { |
||
| 452 | //Course toolbar |
||
| 453 | $show_course_shortcut = CourseHome::show_navigation_tool_shortcuts(); |
||
| 454 | } |
||
| 455 | if (api_get_setting('show_navigation_menu') != 'false') { |
||
| 456 | //Course toolbar |
||
| 457 | $show_course_navigation_menu = CourseHome::show_navigation_menu(); |
||
| 458 | } |
||
| 459 | } |
||
| 460 | $this->assign('show_course_shortcut', $show_course_shortcut); |
||
| 461 | $this->assign('show_course_navigation_menu', $show_course_navigation_menu); |
||
| 462 | } |
||
| 463 | |||
| 464 | /** |
||
| 465 | * @param string $name |
||
| 466 | * |
||
| 467 | * @return string |
||
| 468 | */ |
||
| 469 | public function get_template($name) |
||
| 470 | { |
||
| 471 | if ($name == 'layout/layout_1_col.tpl') { |
||
| 472 | $name = '@ChamiloTheme/Layout/layout_1_col.html.twig'; |
||
| 473 | } |
||
| 474 | |||
| 475 | if ($name == 'layout/layout_2_col.tpl') { |
||
| 476 | $name = '@ChamiloTheme/Layout/layout_2_col.html.twig'; |
||
| 477 | } |
||
| 478 | |||
| 479 | /** |
||
| 480 | * In Chamilo 1.x we use the tpl extension. |
||
| 481 | * In Chamilo 2.x we use twig but using the Symfony2 bridge |
||
| 482 | * In order to don't change all legacy main calls we just replace |
||
| 483 | * tpl with html.twig (the new template location should be: |
||
| 484 | * (src/Chamilo/CoreBundle/Resources/views/default/layout) |
||
| 485 | */ |
||
| 486 | $name = str_replace('.tpl', '.html.twig', $name); |
||
| 487 | |||
| 488 | return '@ChamiloCore/'.$this->templateFolder.'/'.$name; |
||
| 489 | } |
||
| 490 | |||
| 491 | /** |
||
| 492 | * Set course parameters |
||
| 493 | */ |
||
| 494 | private function set_course_parameters() |
||
| 495 | { |
||
| 496 | //Setting course id |
||
| 497 | $course = api_get_course_info(); |
||
| 498 | if (empty($course)) { |
||
| 499 | $this->assign('course_is_set', false); |
||
| 500 | return; |
||
| 501 | } |
||
| 502 | $this->assign('course_is_set', true); |
||
| 503 | $this->course_id = $course['id']; |
||
| 504 | $_c = array( |
||
| 505 | 'id' => $course['id'], |
||
| 506 | 'code' => $course['code'], |
||
| 507 | 'title' => $course['name'], |
||
| 508 | 'visibility' => $course['visibility'], |
||
| 509 | 'language' => $course['language'], |
||
| 510 | 'directory' => $course['directory'], |
||
| 511 | 'session_id' => api_get_session_id(), |
||
| 512 | 'user_is_teacher' => api_is_course_admin(), |
||
| 513 | 'student_view' => (!empty($_GET['isStudentView']) && $_GET['isStudentView'] == 'true'), |
||
| 514 | ); |
||
| 515 | $this->assign('course_code', $course['code']); |
||
| 516 | $this->assign('_c', $_c); |
||
| 517 | } |
||
| 518 | |||
| 519 | /** |
||
| 520 | * Set user parameters |
||
| 521 | */ |
||
| 522 | private function set_user_parameters() |
||
| 523 | { |
||
| 524 | $user_info = array(); |
||
| 525 | $user_info['logged'] = 0; |
||
| 526 | $this->user_is_logged_in = false; |
||
| 527 | if (api_user_is_login()) { |
||
| 528 | $user_info = api_get_user_info(api_get_user_id(), true); |
||
| 529 | $user_info['logged'] = 1; |
||
| 530 | |||
| 531 | $user_info['is_admin'] = 0; |
||
| 532 | if (api_is_platform_admin()) { |
||
| 533 | $user_info['is_admin'] = 1; |
||
| 534 | } |
||
| 535 | |||
| 536 | $user_info['messages_count'] = MessageManager::getCountNewMessages(); |
||
| 537 | $this->user_is_logged_in = true; |
||
| 538 | } |
||
| 539 | // Setting the $_u array that could be use in any template |
||
| 540 | $this->assign('_u', $user_info); |
||
| 541 | } |
||
| 542 | |||
| 543 | /** |
||
| 544 | * Set system parameters |
||
| 545 | */ |
||
| 546 | private function set_system_parameters() |
||
| 547 | { |
||
| 548 | global $_configuration; |
||
| 549 | $this->theme = api_get_visual_theme(); |
||
| 550 | |||
| 551 | //Here we can add system parameters that can be use in any template |
||
| 552 | $_s = array( |
||
| 553 | 'software_name' => $_configuration['software_name'], |
||
| 554 | 'system_version' => $_configuration['system_version'], |
||
| 555 | 'site_name' => api_get_setting('siteName'), |
||
| 556 | 'institution' => api_get_setting('Institution'), |
||
| 557 | 'date' => api_format_date('now', DATE_FORMAT_LONG), |
||
| 558 | 'timezone' => api_get_timezone(), |
||
| 559 | 'gamification_mode' => api_get_setting('gamification_mode') |
||
| 560 | ); |
||
| 561 | $this->assign('_s', $_s); |
||
| 562 | } |
||
| 563 | |||
| 564 | /** |
||
| 565 | * Set legacy twig globals in order to be hook in the LegacyListener.php |
||
| 566 | * @return array |
||
| 567 | */ |
||
| 568 | public static function getGlobals() |
||
| 569 | { |
||
| 570 | $_p = array( |
||
| 571 | 'web' => api_get_path(WEB_PATH), |
||
| 572 | 'web_relative' => api_get_path(REL_PATH), |
||
| 573 | 'web_course' => api_get_path(WEB_COURSE_PATH), |
||
| 574 | 'web_main' => api_get_path(WEB_CODE_PATH), |
||
| 575 | 'web_css' => api_get_path(WEB_CSS_PATH), |
||
| 576 | //'web_css_theme' => api_get_path(WEB_CSS_PATH) . 'themes/' . $this->theme . '/', |
||
| 577 | 'web_ajax' => api_get_path(WEB_AJAX_PATH), |
||
| 578 | 'web_img' => api_get_path(WEB_IMG_PATH), |
||
| 579 | 'web_plugin' => api_get_path(WEB_PLUGIN_PATH), |
||
| 580 | 'web_plugin_asset' => api_get_path(WEB_PLUGIN_ASSET_PATH), |
||
| 581 | 'web_lib' => api_get_path(WEB_LIBRARY_PATH), |
||
| 582 | 'web_upload' => api_get_path(WEB_UPLOAD_PATH), |
||
| 583 | 'web_self' => api_get_self(), |
||
| 584 | 'web_query_vars' => api_htmlentities($_SERVER['QUERY_STRING']), |
||
| 585 | 'web_self_query_vars' => api_htmlentities($_SERVER['REQUEST_URI']), |
||
| 586 | 'web_cid_query' => api_get_cidreq(), |
||
| 587 | ); |
||
| 588 | |||
| 589 | $_s = array( |
||
| 590 | 'software_name' => api_get_configuration_value('software_name'), |
||
| 591 | 'system_version' => api_get_configuration_value('system_version'), |
||
| 592 | 'site_name' => api_get_setting('siteName'), |
||
| 593 | 'institution' => api_get_setting('Institution'), |
||
| 594 | 'date' => api_format_date('now', DATE_FORMAT_LONG), |
||
| 595 | 'timezone' => api_get_timezone(), |
||
| 596 | 'gamification_mode' => api_get_setting('gamification_mode') |
||
| 597 | ); |
||
| 598 | |||
| 599 | //$user_info = api_get_user_info(); |
||
| 600 | |||
| 601 | return [ |
||
| 602 | '_p' => $_p, |
||
| 603 | '_s' => $_s, |
||
| 604 | // '_u' => $user_info, |
||
| 605 | 'template' => 'default' // @todo setup template folder in config.yml; |
||
| 606 | ]; |
||
| 607 | } |
||
| 608 | |||
| 609 | /** |
||
| 610 | * Set theme, include mainstream CSS files |
||
| 611 | * @return void |
||
| 612 | * @see setCssCustomFiles() for additional CSS sheets |
||
| 613 | */ |
||
| 614 | public function setCssFiles() |
||
| 615 | { |
||
| 616 | return; |
||
| 617 | global $disable_js_and_css_files; |
||
| 618 | $css = array(); |
||
| 619 | |||
| 620 | $this->theme = api_get_visual_theme(); |
||
| 621 | |||
| 622 | if (!empty($this->preview_theme)) { |
||
| 623 | $this->theme = $this->preview_theme; |
||
| 624 | } |
||
| 625 | |||
| 626 | // Default CSS Bootstrap |
||
| 627 | $bowerCSSFiles = [ |
||
| 628 | 'bootstrap-daterangepicker/daterangepicker-bs3.css', |
||
| 629 | 'fontawesome/css/font-awesome.min.css', |
||
| 630 | 'jquery-ui/themes/smoothness/theme.css', |
||
| 631 | 'jquery-ui/themes/smoothness/jquery-ui.min.css', |
||
| 632 | 'mediaelement/build/mediaelementplayer.min.css', |
||
| 633 | 'jqueryui-timepicker-addon/dist/jquery-ui-timepicker-addon.min.css', |
||
| 634 | 'bootstrap/dist/css/bootstrap.min.css', |
||
| 635 | 'jquery.scrollbar/jquery.scrollbar.css', |
||
| 636 | ]; |
||
| 637 | |||
| 638 | foreach ($bowerCSSFiles as $file) { |
||
| 639 | $css[] = api_get_path(WEB_PATH).'web/assets/'.$file; |
||
| 640 | } |
||
| 641 | $css[] = api_get_path(WEB_LIBRARY_PATH) . 'javascript/bootstrap-select/css/bootstrap-select.min.css'; |
||
| 642 | $css[] = api_get_path(WEB_LIBRARY_PATH) . 'javascript/chosen/chosen.css'; |
||
| 643 | $css[] = api_get_path(WEB_LIBRARY_PATH) . 'javascript/tag/style.css'; |
||
| 644 | |||
| 645 | if (api_is_global_chat_enabled()) { |
||
| 646 | $css[] = api_get_path(WEB_LIBRARY_PATH) . 'javascript/chat/css/chat.css'; |
||
| 647 | } |
||
| 648 | |||
| 649 | //THEME CSS STYLE |
||
| 650 | // $css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH).'responsive.css'); |
||
| 651 | |||
| 652 | $css_file_to_string = null; |
||
| 653 | foreach ($css as $file) { |
||
| 654 | $css_file_to_string .= api_get_css($file); |
||
| 655 | } |
||
| 656 | |||
| 657 | if (!$disable_js_and_css_files) { |
||
| 658 | $this->assign('css_static_file_to_string', $css_file_to_string); |
||
| 659 | } |
||
| 660 | } |
||
| 661 | |||
| 662 | /** |
||
| 663 | * |
||
| 664 | */ |
||
| 665 | public function setCSSEditor() |
||
| 666 | { |
||
| 667 | return; |
||
| 668 | $cssEditor = api_get_cdn_path(api_get_path(WEB_CSS_PATH).'editor.css'); |
||
| 669 | if (is_file(api_get_path(SYS_CSS_PATH).'themes/'.$this->theme.'/editor.css')) { |
||
| 670 | $cssEditor = api_get_path(WEB_CSS_PATH).'themes/'.$this->theme.'/editor.css'; |
||
| 671 | } |
||
| 672 | |||
| 673 | $this->assign('cssEditor', $cssEditor); |
||
| 674 | } |
||
| 675 | |||
| 676 | /** |
||
| 677 | * Prepare custom CSS to be added at the very end of the <head> section |
||
| 678 | * @return void |
||
| 679 | * @see setCssFiles() for the mainstream CSS files |
||
| 680 | */ |
||
| 681 | public function setCssCustomFiles() |
||
| 682 | { |
||
| 683 | return; |
||
| 684 | global $disable_js_and_css_files; |
||
| 685 | // Base CSS |
||
| 686 | |||
| 687 | $css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH).'base.css'); |
||
| 688 | |||
| 689 | View Code Duplication | if ($this->show_learnpath) { |
|
| 690 | $css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH).'scorm.css'); |
||
| 691 | if (is_file(api_get_path(SYS_CSS_PATH).'themes/'.$this->theme.'/learnpath.css')) { |
||
| 692 | $css[] = api_get_path(WEB_CSS_PATH).'themes/'.$this->theme.'/learnpath.css'; |
||
| 693 | } |
||
| 694 | } |
||
| 695 | |||
| 696 | View Code Duplication | if (is_file(api_get_path(SYS_CSS_PATH).'themes/'.$this->theme.'/editor.css')) { |
|
| 697 | $css[] = api_get_path(WEB_CSS_PATH).'themes/'.$this->theme.'/editor.css'; |
||
| 698 | }else{ |
||
| 699 | $css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH).'editor.css'); |
||
| 700 | } |
||
| 701 | |||
| 702 | $css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH).'themes/'.$this->theme.'/default.css'); |
||
| 703 | |||
| 704 | $css_file_to_string = null; |
||
| 705 | foreach ($css as $file) { |
||
| 706 | $css_file_to_string .= api_get_css($file); |
||
| 707 | } |
||
| 708 | // @todo move this somewhere else. Special fix when using tablets in order to see the text near icons |
||
| 709 | if (SHOW_TEXT_NEAR_ICONS == true) { |
||
| 710 | //hack in order to fix the actions buttons |
||
| 711 | $css_file_to_string .= '<style> |
||
| 712 | .td_actions a { |
||
| 713 | float:left; |
||
| 714 | width:100%; |
||
| 715 | } |
||
| 716 | .forum_message_left a { |
||
| 717 | float:left; |
||
| 718 | width:100%; |
||
| 719 | } |
||
| 720 | </style>'; |
||
| 721 | } |
||
| 722 | |||
| 723 | $navigator_info = api_get_navigator(); |
||
| 724 | if ($navigator_info['name'] == 'Internet Explorer' && $navigator_info['version'] == '6') { |
||
| 725 | $css_file_to_string .= 'img, div { behavior: url('.api_get_path(WEB_LIBRARY_PATH).'javascript/iepngfix/iepngfix.htc) } '."\n"; |
||
| 726 | } |
||
| 727 | |||
| 728 | if (!$disable_js_and_css_files) { |
||
| 729 | $this->assign('css_custom_file_to_string', $css_file_to_string); |
||
| 730 | |||
| 731 | $style_print = ''; |
||
| 732 | if (is_readable(api_get_path(SYS_CSS_PATH).$this->theme.'/print.css')) { |
||
| 733 | $style_print = api_get_css(api_get_cdn_path(api_get_path(WEB_CSS_PATH) . $this->theme . '/print.css'), |
||
| 734 | 'print'); |
||
| 735 | } |
||
| 736 | $this->assign('css_style_print', $style_print); |
||
| 737 | } |
||
| 738 | |||
| 739 | // Logo |
||
| 740 | /*$logo = return_logo($this->theme); |
||
| 741 | $this->assign('logo', $logo);*/ |
||
| 742 | |||
| 743 | $this->assign('show_media_element', 1); |
||
| 744 | } |
||
| 745 | |||
| 746 | /** |
||
| 747 | * Declare and define the template variable that will be used to load |
||
| 748 | * javascript libraries in the header. |
||
| 749 | */ |
||
| 750 | public function set_js_files() |
||
| 751 | { |
||
| 752 | global $disable_js_and_css_files, $htmlHeadXtra; |
||
| 753 | |||
| 754 | $isoCode = api_get_language_isocode(); |
||
| 755 | |||
| 756 | $selectLink = 'bootstrap-select/js/i18n/defaults-' . $isoCode . '_' . strtoupper($isoCode) . '.min.js'; |
||
| 757 | |||
| 758 | if ($isoCode == 'en') { |
||
| 759 | $selectLink = 'bootstrap-select/js/i18n/defaults-' . $isoCode . '_US.min.js'; |
||
| 760 | } |
||
| 761 | // JS files |
||
| 762 | $js_files = array( |
||
| 763 | 'chosen/chosen.jquery.min.js', |
||
| 764 | 'bootstrap-select/js/bootstrap-select.min.js', |
||
| 765 | $selectLink |
||
| 766 | ); |
||
| 767 | |||
| 768 | $viewBySession = api_get_setting('my_courses_view_by_session') === 'true'; |
||
| 769 | |||
| 770 | View Code Duplication | if (api_is_global_chat_enabled() || $viewBySession) { |
|
| 771 | // Do not include the global chat in LP |
||
| 772 | if ($this->show_learnpath == false && |
||
| 773 | $this->show_footer == true && |
||
| 774 | $this->hide_global_chat == false |
||
| 775 | ) { |
||
| 776 | $js_files[] = 'chat/js/chat.js'; |
||
| 777 | } |
||
| 778 | } |
||
| 779 | |||
| 780 | if (api_get_setting('accessibility_font_resize') == 'true') { |
||
| 781 | $js_files[] = 'fontresize.js'; |
||
| 782 | } |
||
| 783 | |||
| 784 | // Do not use minified version - generates errors (at least in the skills wheel) |
||
| 785 | $js_files[] = 'tag/jquery.fcbkcomplete.js'; |
||
| 786 | |||
| 787 | $js_file_to_string = null; |
||
| 788 | |||
| 789 | $bowerJsFiles = [ |
||
| 790 | 'modernizr/modernizr.js', |
||
| 791 | 'jquery/dist/jquery.min.js', |
||
| 792 | 'bootstrap/dist/js/bootstrap.min.js', |
||
| 793 | 'jquery-ui/jquery-ui.min.js', |
||
| 794 | 'moment/min/moment-with-locales.min.js', |
||
| 795 | 'bootstrap-daterangepicker/daterangepicker.js', |
||
| 796 | 'jquery-timeago/jquery.timeago.js', |
||
| 797 | 'mediaelement/build/mediaelement-and-player.min.js', |
||
| 798 | 'jqueryui-timepicker-addon/dist/jquery-ui-timepicker-addon.min.js', |
||
| 799 | 'image-map-resizer/js/imageMapResizer.min.js', |
||
| 800 | 'jquery.scrollbar/jquery.scrollbar.min.js', |
||
| 801 | 'readmore-js/readmore.min.js' |
||
| 802 | ]; |
||
| 803 | if (CHAMILO_LOAD_WYSIWYG == true) { |
||
| 804 | $bowerJsFiles[] = 'ckeditor/ckeditor.js'; |
||
| 805 | } |
||
| 806 | |||
| 807 | if (api_get_setting('include_asciimathml_script') == 'true') { |
||
| 808 | $bowerJsFiles[] = 'MathJax/MathJax.js?config=AM_HTMLorMML'; |
||
| 809 | } |
||
| 810 | |||
| 811 | if ($isoCode != 'en') { |
||
| 812 | $bowerJsFiles[] = 'jqueryui-timepicker-addon/dist/i18n/jquery-ui-timepicker-' . $isoCode . '.js'; |
||
| 813 | $bowerJsFiles[] = 'jquery-ui/ui/minified/i18n/datepicker-' . $isoCode . '.min.js'; |
||
| 814 | } |
||
| 815 | |||
| 816 | foreach ($bowerJsFiles as $file) { |
||
| 817 | $js_file_to_string .= '<script type="text/javascript" src="'.api_get_path(WEB_PATH).'web/assets/'.$file.'"></script>'."\n"; |
||
| 818 | } |
||
| 819 | |||
| 820 | foreach ($js_files as $file) { |
||
| 821 | $js_file_to_string .= api_get_js($file); |
||
| 822 | } |
||
| 823 | |||
| 824 | // Loading email_editor js |
||
| 825 | if (!api_is_anonymous() && api_get_setting('allow_email_editor') == 'true') { |
||
| 826 | $template = $this->get_template('mail_editor/email_link.js.tpl'); |
||
| 827 | $js_file_to_string .= $this->fetch($template); |
||
| 828 | } |
||
| 829 | |||
| 830 | if (!$disable_js_and_css_files) { |
||
| 831 | $this->assign('js_file_to_string', $js_file_to_string); |
||
| 832 | |||
| 833 | //Adding jquery ui by default |
||
| 834 | $extra_headers = api_get_jquery_ui_js(); |
||
| 835 | |||
| 836 | //$extra_headers = ''; |
||
| 837 | if (isset($htmlHeadXtra) && $htmlHeadXtra) { |
||
| 838 | foreach ($htmlHeadXtra as & $this_html_head) { |
||
| 839 | $extra_headers .= $this_html_head."\n"; |
||
| 840 | } |
||
| 841 | } |
||
| 842 | $this->assign('extra_headers', $extra_headers); |
||
| 843 | } |
||
| 844 | } |
||
| 845 | |||
| 846 | /** |
||
| 847 | * Special function to declare last-minute JS libraries which depend on |
||
| 848 | * other things to be declared first. In particular, it might be useful |
||
| 849 | * under IE9 with compatibility mode, which for some reason is getting |
||
| 850 | * upset when a variable is used in a function (even if not used yet) |
||
| 851 | * when this variable hasn't been defined yet. |
||
| 852 | */ |
||
| 853 | public function set_js_files_post() |
||
| 854 | { |
||
| 855 | global $disable_js_and_css_files, $htmlHeadXtra; |
||
| 856 | $js_files = array(); |
||
| 857 | View Code Duplication | if (api_is_global_chat_enabled()) { |
|
| 858 | //Do not include the global chat in LP |
||
| 859 | if ($this->show_learnpath == false && $this->show_footer == true && $this->hide_global_chat == false) { |
||
| 860 | $js_files[] = 'chat/js/chat.js'; |
||
| 861 | } |
||
| 862 | } |
||
| 863 | $js_file_to_string = null; |
||
| 864 | |||
| 865 | foreach ($js_files as $js_file) { |
||
| 866 | $js_file_to_string .= api_get_js($js_file); |
||
| 867 | } |
||
| 868 | if (!$disable_js_and_css_files) { |
||
| 869 | $this->assign('js_file_to_string_post', $js_file_to_string); |
||
| 870 | } |
||
| 871 | } |
||
| 872 | |||
| 873 | /** |
||
| 874 | * Set header parameters |
||
| 875 | * @param bool $sendHeaders send headers |
||
| 876 | */ |
||
| 877 | private function set_header_parameters($sendHeaders) |
||
| 878 | { |
||
| 879 | |||
| 880 | global $httpHeadXtra, $interbreadcrumb, $language_file, $_configuration, $this_section; |
||
| 881 | $_course = api_get_course_info(); |
||
| 882 | $help = $this->help; |
||
| 883 | $nameTools = $this->title; |
||
| 884 | //$navigation = return_navigation_array(); |
||
| 885 | $navigation = []; |
||
| 886 | //$this->menu_navigation = $navigation['menu_navigation']; |
||
| 887 | |||
| 888 | $this->assign('system_charset', api_get_system_encoding()); |
||
| 889 | |||
| 890 | if (isset($httpHeadXtra) && $httpHeadXtra) { |
||
| 891 | foreach ($httpHeadXtra as & $thisHttpHead) { |
||
| 892 | header($thisHttpHead); |
||
| 893 | } |
||
| 894 | } |
||
| 895 | |||
| 896 | $this->assign( |
||
| 897 | 'online_button', |
||
| 898 | Display::return_icon('statusonline.png', null, [], ICON_SIZE_ATOM) |
||
| 899 | ); |
||
| 900 | $this->assign( |
||
| 901 | 'offline_button', |
||
| 902 | Display::return_icon('statusoffline.png', null, [], ICON_SIZE_ATOM) |
||
| 903 | ); |
||
| 904 | |||
| 905 | // Get language iso-code for this page - ignore errors |
||
| 906 | $this->assign('document_language', api_get_language_isocode()); |
||
| 907 | |||
| 908 | $course_title = isset($_course['name']) ? $_course['name'] : null; |
||
| 909 | |||
| 910 | $title_list = array(); |
||
| 911 | |||
| 912 | $title_list[] = api_get_setting('Institution'); |
||
| 913 | $title_list[] = api_get_setting('siteName'); |
||
| 914 | |||
| 915 | if (!empty($course_title)) { |
||
| 916 | $title_list[] = $course_title; |
||
| 917 | } |
||
| 918 | if ($nameTools != '') { |
||
| 919 | $title_list[] = $nameTools; |
||
| 920 | } |
||
| 921 | |||
| 922 | $title_string = ''; |
||
| 923 | for ($i = 0; $i < count($title_list); $i++) { |
||
| 924 | $title_string .= $title_list[$i]; |
||
| 925 | if (isset($title_list[$i + 1])) { |
||
| 926 | $item = trim($title_list[$i + 1]); |
||
| 927 | if (!empty($item)) { |
||
| 928 | $title_string .= ' - '; |
||
| 929 | } |
||
| 930 | } |
||
| 931 | } |
||
| 932 | |||
| 933 | $this->assign('title_string', $title_string); |
||
| 934 | |||
| 935 | //Setting the theme and CSS files |
||
| 936 | $css = $this->setCssFiles(); |
||
| 937 | $this->set_js_files(); |
||
| 938 | $this->setCssCustomFiles($css); |
||
| 939 | //$this->set_js_files_post(); |
||
| 940 | |||
| 941 | $browser = api_browser_support('check_browser'); |
||
| 942 | if ($browser[0] == 'Internet Explorer' && $browser[1] >= '11') { |
||
| 943 | $browser_head = '<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9" />'; |
||
| 944 | $this->assign('browser_specific_head', $browser_head); |
||
| 945 | } |
||
| 946 | |||
| 947 | // Implementation of prefetch. |
||
| 948 | // See http://cdn.chamilo.org/main/img/online.png for details |
||
| 949 | $prefetch = ''; |
||
| 950 | if (!empty($_configuration['cdn_enable'])) { |
||
| 951 | $prefetch .= '<meta http-equiv="x-dns-prefetch-control" content="on">'; |
||
| 952 | foreach ($_configuration['cdn'] as $host => $exts) { |
||
| 953 | $prefetch .= '<link rel="dns-prefetch" href="'.$host.'">'; |
||
| 954 | } |
||
| 955 | } |
||
| 956 | |||
| 957 | $this->assign('prefetch', $prefetch); |
||
| 958 | $this->assign('text_direction', api_get_text_direction()); |
||
| 959 | $this->assign('section_name', 'section-'.$this_section); |
||
| 960 | |||
| 961 | //Defaul root chamilo favicon |
||
| 962 | $favico = '<link rel="shortcut icon" href="' . api_get_path(WEB_PATH) . 'favicon.ico" type="image/x-icon" />'; |
||
| 963 | |||
| 964 | //Added to verify if in the current Chamilo Theme exist a favicon |
||
| 965 | $favicoThemeUrl = api_get_path(SYS_CSS_PATH) . 'themes/' . $this->theme . '/images/'; |
||
| 966 | |||
| 967 | //If exist pick the current chamilo theme favicon |
||
| 968 | if (is_file($favicoThemeUrl . 'favicon.ico')) { |
||
| 969 | $favico = '<link rel="shortcut icon" href="' . api_get_path(WEB_CSS_PATH). 'themes/' . $this->theme . '/images/favicon.ico" type="image/x-icon" />'; |
||
| 970 | } |
||
| 971 | |||
| 972 | if (api_is_multiple_url_enabled()) { |
||
| 973 | $access_url_id = api_get_current_access_url_id(); |
||
| 974 | if ($access_url_id != -1) { |
||
| 975 | $url_info = api_get_access_url($access_url_id); |
||
| 976 | $url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $url_info['url'])); |
||
| 977 | $clean_url = api_replace_dangerous_char($url); |
||
| 978 | $clean_url = str_replace('/', '-', $clean_url); |
||
| 979 | $clean_url .= '/'; |
||
| 980 | $homep = api_get_path(REL_PATH).'home/'.$clean_url; //homep for Home Path |
||
| 981 | $icon_real_homep = api_get_path(SYS_APP_PATH).'home/'.$clean_url; |
||
| 982 | |||
| 983 | //we create the new dir for the new sites |
||
| 984 | if (is_file($icon_real_homep.'favicon.ico')) { |
||
| 985 | $favico = '<link rel="shortcut icon" href="'.$homep.'favicon.ico" type="image/x-icon" />'; |
||
| 986 | } |
||
| 987 | } |
||
| 988 | } |
||
| 989 | |||
| 990 | $this->assign('favico', $favico); |
||
| 991 | $this->setHelp(); |
||
| 992 | |||
| 993 | //@todo move this in the template |
||
| 994 | $rightFloatMenu = ''; |
||
| 995 | $iconBug = Display::return_icon('bug.png', get_lang('ReportABug'), [], ICON_SIZE_LARGE); |
||
| 996 | if (api_get_setting('show_link_bug_notification') == 'true' && $this->user_is_logged_in) { |
||
| 997 | $rightFloatMenu = '<div class="report"> |
||
| 998 | <a href="https://github.com/chamilo/chamilo-lms/wiki/How-to-report-issues" target="_blank"> |
||
| 999 | '. $iconBug . ' |
||
| 1000 | </a> |
||
| 1001 | </div>'; |
||
| 1002 | } |
||
| 1003 | |||
| 1004 | if (api_get_setting('show_link_ticket_notification') == 'true' && $this->user_is_logged_in) { |
||
| 1005 | // by default is project_id = 1 |
||
| 1006 | $iconTicket = Display::return_icon('bug.png', get_lang('Ticket'), [], ICON_SIZE_LARGE); |
||
| 1007 | $courseInfo = api_get_course_info(); |
||
| 1008 | $courseParams = ''; |
||
| 1009 | if (!empty($courseInfo)) { |
||
| 1010 | $courseParams = api_get_cidreq(); |
||
| 1011 | } |
||
| 1012 | $url = api_get_path(WEB_CODE_PATH).'ticket/tickets.php?project_id=1&'.$courseParams; |
||
| 1013 | $rightFloatMenu .= '<div class="report"> |
||
| 1014 | <a href="'.$url.'" target="_blank"> |
||
| 1015 | '. $iconTicket . ' |
||
| 1016 | </a> |
||
| 1017 | </div>'; |
||
| 1018 | } |
||
| 1019 | |||
| 1020 | $this->assign('bug_notification', $rightFloatMenu); |
||
| 1021 | |||
| 1022 | //$notification = returnNotificationMenu(); |
||
| 1023 | $this->assign('notification_menu', ''); |
||
| 1024 | |||
| 1025 | $resize = ''; |
||
| 1026 | if (api_get_setting('accessibility_font_resize') == 'true') { |
||
| 1027 | $resize .= '<div class="resize_font">'; |
||
| 1028 | $resize .= '<div class="btn-group">'; |
||
| 1029 | $resize .= '<a title="'.get_lang('DecreaseFontSize').'" href="#" class="decrease_font btn btn-default"><em class="fa fa-font"></em></a>'; |
||
| 1030 | $resize .= '<a title="'.get_lang('ResetFontSize').'" href="#" class="reset_font btn btn-default"><em class="fa fa-font"></em></a>'; |
||
| 1031 | $resize .= '<a title="'.get_lang('IncreaseFontSize').'" href="#" class="increase_font btn btn-default"><em class="fa fa-font"></em></a>'; |
||
| 1032 | $resize .= '</div>'; |
||
| 1033 | $resize .= '</div>'; |
||
| 1034 | } |
||
| 1035 | $this->assign('accessibility', $resize); |
||
| 1036 | |||
| 1037 | // Preparing values for the menu |
||
| 1038 | |||
| 1039 | // Logout link |
||
| 1040 | $hideLogout = api_get_setting('hide_logout_button'); |
||
| 1041 | if ($hideLogout === 'true') { |
||
| 1042 | $this->assign('logout_link', null); |
||
| 1043 | } else { |
||
| 1044 | $this->assign('logout_link', api_get_path(WEB_PATH).'index.php?logout=logout&uid='.api_get_user_id()); |
||
| 1045 | } |
||
| 1046 | |||
| 1047 | //Profile link |
||
| 1048 | if (api_get_setting('allow_social_tool') == 'true') { |
||
| 1049 | $profile_url = api_get_path(WEB_CODE_PATH).'social/home.php'; |
||
| 1050 | |||
| 1051 | } else { |
||
| 1052 | $profile_url = api_get_path(WEB_CODE_PATH).'auth/profile.php'; |
||
| 1053 | |||
| 1054 | } |
||
| 1055 | |||
| 1056 | $this->assign('profile_url', $profile_url); |
||
| 1057 | |||
| 1058 | //Message link |
||
| 1059 | $message_link = null; |
||
| 1060 | $message_url = null; |
||
| 1061 | if (api_get_setting('allow_message_tool') == 'true') { |
||
| 1062 | $message_url = api_get_path(WEB_CODE_PATH).'messages/inbox.php'; |
||
| 1063 | $message_link = '<a href="'.api_get_path(WEB_CODE_PATH).'messages/inbox.php">'.get_lang('Inbox').'</a>'; |
||
| 1064 | } |
||
| 1065 | $this->assign('message_link', $message_link); |
||
| 1066 | $this->assign('message_url', $message_url); |
||
| 1067 | |||
| 1068 | // Certificate Link |
||
| 1069 | |||
| 1070 | $allow = api_get_configuration_value('hide_my_certificate_link'); |
||
| 1071 | if ($allow === false) { |
||
| 1072 | $certificateUrl = api_get_path(WEB_CODE_PATH).'gradebook/my_certificates.php'; |
||
| 1073 | $certificateLink = Display::url( |
||
| 1074 | get_lang('MyCertificates'), |
||
| 1075 | $certificateUrl |
||
| 1076 | ); |
||
| 1077 | $this->assign('certificate_link', $certificateLink); |
||
| 1078 | $this->assign('certificate_url', $certificateUrl); |
||
| 1079 | } |
||
| 1080 | |||
| 1081 | $institution = api_get_setting('Institution'); |
||
| 1082 | $portal_name = empty($institution) ? api_get_setting('siteName') : $institution; |
||
| 1083 | |||
| 1084 | $this->assign('portal_name', $portal_name); |
||
| 1085 | |||
| 1086 | //Menu |
||
| 1087 | //$menu = menuArray(); |
||
| 1088 | $this->assign('menu', ''); |
||
| 1089 | |||
| 1090 | // Setting notifications |
||
| 1091 | $count_unread_message = 0; |
||
| 1092 | if (api_get_setting('allow_message_tool') == 'true') { |
||
| 1093 | // get count unread message and total invitations |
||
| 1094 | $count_unread_message = MessageManager::get_number_of_messages(true); |
||
| 1095 | } |
||
| 1096 | |||
| 1097 | $total_invitations = 0; |
||
| 1098 | if (api_get_setting('allow_social_tool') == 'true') { |
||
| 1099 | $number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id( |
||
| 1100 | api_get_user_id() |
||
| 1101 | ); |
||
| 1102 | $usergroup = new UserGroup(); |
||
| 1103 | $group_pending_invitations = $usergroup->get_groups_by_user( |
||
| 1104 | api_get_user_id(), |
||
| 1105 | GROUP_USER_PERMISSION_PENDING_INVITATION, |
||
| 1106 | false |
||
| 1107 | ); |
||
| 1108 | if (!empty($group_pending_invitations)) { |
||
| 1109 | $group_pending_invitations = count($group_pending_invitations); |
||
| 1110 | } else { |
||
| 1111 | $group_pending_invitations = 0; |
||
| 1112 | } |
||
| 1113 | $total_invitations = intval($number_of_new_messages_of_friend) + $group_pending_invitations + intval($count_unread_message); |
||
| 1114 | } |
||
| 1115 | $total_invitations = (!empty($total_invitations) ? Display::badge($total_invitations) : null); |
||
| 1116 | |||
| 1117 | $this->assign('user_notifications', $total_invitations); |
||
| 1118 | |||
| 1119 | |||
| 1120 | // Block Breadcrumb |
||
| 1121 | //$breadcrumb = return_breadcrumb($interbreadcrumb, $language_file, $nameTools); |
||
| 1122 | $breadcrumb = ''; |
||
| 1123 | $this->assign('breadcrumb', $breadcrumb); |
||
| 1124 | |||
| 1125 | //Extra content |
||
| 1126 | $extra_header = null; |
||
| 1127 | if (!api_is_platform_admin()) { |
||
| 1128 | $extra_header = trim(api_get_setting('header_extra_content')); |
||
| 1129 | } |
||
| 1130 | $this->assign('header_extra_content', $extra_header); |
||
| 1131 | |||
| 1132 | if ($sendHeaders) { |
||
| 1133 | header('Content-Type: text/html; charset='.api_get_system_encoding()); |
||
| 1134 | header( |
||
| 1135 | 'X-Powered-By: '.$_configuration['software_name'].' '.substr($_configuration['system_version'], 0, 1) |
||
| 1136 | ); |
||
| 1137 | } |
||
| 1138 | |||
| 1139 | $socialMeta = ''; |
||
| 1140 | $metaTitle = api_get_setting('meta_title'); |
||
| 1141 | if (!empty($metaTitle)) { |
||
| 1142 | $socialMeta .= '<meta name="twitter:card" content="summary" />' . "\n"; |
||
| 1143 | $metaSite = api_get_setting('meta_twitter_site'); |
||
| 1144 | if (!empty($metaSite)) { |
||
| 1145 | $socialMeta .= '<meta name="twitter:site" content="' . $metaSite . '" />' . "\n"; |
||
| 1146 | $metaCreator = api_get_setting('meta_twitter_creator'); |
||
| 1147 | if (!empty($metaCreator)) { |
||
| 1148 | $socialMeta .= '<meta name="twitter:creator" content="' . $metaCreator . '" />' . "\n"; |
||
| 1149 | } |
||
| 1150 | } |
||
| 1151 | |||
| 1152 | // The user badge page emits its own meta tags, so if this is |
||
| 1153 | // enabled, ignore the global ones |
||
| 1154 | $userId = isset($_GET['user']) ? intval($_GET['user']) : 0; |
||
| 1155 | $skillId = isset($_GET['skill']) ? intval($_GET['skill']) : 0; |
||
| 1156 | |||
| 1157 | if (!$userId && !$skillId) { |
||
| 1158 | // no combination of user and skill ID has been defined, |
||
| 1159 | // so print the normal OpenGraph meta tags |
||
| 1160 | $socialMeta .= '<meta property="og:title" content="' . $metaTitle . '" />' . "\n"; |
||
| 1161 | $socialMeta .= '<meta property="og:url" content="' . api_get_path(WEB_PATH) . '" />' . "\n"; |
||
| 1162 | |||
| 1163 | $metaDescription = api_get_setting('meta_description'); |
||
| 1164 | if (!empty($metaDescription)) { |
||
| 1165 | $socialMeta .= '<meta property="og:description" content="' . $metaDescription . '" />' . "\n"; |
||
| 1166 | } |
||
| 1167 | |||
| 1168 | $metaImage = api_get_setting('meta_image_path'); |
||
| 1169 | if (!empty($metaImage)) { |
||
| 1170 | if (is_file(api_get_path(SYS_PATH) . $metaImage)) { |
||
| 1171 | $path = api_get_path(WEB_PATH) . $metaImage; |
||
| 1172 | $socialMeta .= '<meta property="og:image" content="' . $path . '" />' . "\n"; |
||
| 1173 | } |
||
| 1174 | } |
||
| 1175 | } |
||
| 1176 | } |
||
| 1177 | |||
| 1178 | $this->assign('social_meta', $socialMeta); |
||
| 1179 | } |
||
| 1180 | |||
| 1181 | /** |
||
| 1182 | * Set footer parameters |
||
| 1183 | */ |
||
| 1184 | private function set_footer_parameters() |
||
| 1185 | { |
||
| 1186 | if (api_get_setting('show_administrator_data') === 'true') { |
||
| 1187 | $firstName = api_get_setting('administratorName'); |
||
| 1188 | $lastName = api_get_setting('administratorSurname'); |
||
| 1189 | |||
| 1190 | if (!empty($firstName) && !empty($lastName)) { |
||
| 1191 | $name = api_get_person_name($firstName, $lastName); |
||
| 1192 | } else { |
||
| 1193 | $name = $lastName; |
||
| 1194 | if (empty($lastName)) { |
||
| 1195 | $name = $firstName; |
||
| 1196 | } |
||
| 1197 | } |
||
| 1198 | |||
| 1199 | $adminName = ''; |
||
| 1200 | // Administrator name |
||
| 1201 | if (!empty($name)) { |
||
| 1202 | $adminName = get_lang('Manager').' : '. |
||
| 1203 | Display::encrypted_mailto_link( |
||
| 1204 | api_get_setting('emailAdministrator'), |
||
| 1205 | $name |
||
| 1206 | ); |
||
| 1207 | } |
||
| 1208 | $this->assign('administrator_name', $adminName); |
||
| 1209 | } |
||
| 1210 | |||
| 1211 | // Loading footer extra content |
||
| 1212 | if (!api_is_platform_admin()) { |
||
| 1213 | $extra_footer = trim(api_get_setting('footer_extra_content')); |
||
| 1214 | if (!empty($extra_footer)) { |
||
| 1215 | $this->assign('footer_extra_content', $extra_footer); |
||
| 1216 | } |
||
| 1217 | } |
||
| 1218 | |||
| 1219 | // Tutor name |
||
| 1220 | if (api_get_setting('show_tutor_data') == 'true') { |
||
| 1221 | // Course manager |
||
| 1222 | $courseId = api_get_course_int_id(); |
||
| 1223 | $id_session = api_get_session_id(); |
||
| 1224 | if (!empty($courseId)) { |
||
| 1225 | $tutor_data = ''; |
||
| 1226 | if ($id_session != 0) { |
||
| 1227 | $coachs_email = CourseManager::get_email_of_tutor_to_session( |
||
| 1228 | $id_session, |
||
| 1229 | $courseId |
||
| 1230 | ); |
||
| 1231 | $email_link = array(); |
||
| 1232 | foreach ($coachs_email as $coach) { |
||
| 1233 | $email_link[] = Display::encrypted_mailto_link($coach['email'], $coach['complete_name']); |
||
| 1234 | } |
||
| 1235 | if (count($coachs_email) > 1) { |
||
| 1236 | $tutor_data .= get_lang('Coachs').' : '; |
||
| 1237 | $tutor_data .= array_to_string($email_link, CourseManager::USER_SEPARATOR); |
||
| 1238 | } elseif (count($coachs_email) == 1) { |
||
| 1239 | $tutor_data .= get_lang('Coach').' : '; |
||
| 1240 | $tutor_data .= array_to_string($email_link, CourseManager::USER_SEPARATOR); |
||
| 1241 | } elseif (count($coachs_email) == 0) { |
||
| 1242 | $tutor_data .= ''; |
||
| 1243 | } |
||
| 1244 | } |
||
| 1245 | $this->assign('session_teachers', $tutor_data); |
||
| 1246 | } |
||
| 1247 | } |
||
| 1248 | |||
| 1249 | if (api_get_setting('show_teacher_data') == 'true') { |
||
| 1250 | // course manager |
||
| 1251 | $courseId = api_get_course_int_id(); |
||
| 1252 | if (!empty($courseId)) { |
||
| 1253 | $teacher_data = ''; |
||
| 1254 | $mail = CourseManager::get_emails_of_tutors_to_course($courseId); |
||
| 1255 | if (!empty($mail)) { |
||
| 1256 | $teachers_parsed = array(); |
||
| 1257 | foreach ($mail as $value) { |
||
| 1258 | foreach ($value as $email => $name) { |
||
| 1259 | $teachers_parsed[] = Display::encrypted_mailto_link($email, $name); |
||
| 1260 | } |
||
| 1261 | } |
||
| 1262 | $label = get_lang('Teacher'); |
||
| 1263 | if (count($mail) > 1) { |
||
| 1264 | $label = get_lang('Teachers'); |
||
| 1265 | } |
||
| 1266 | $teacher_data .= $label.' : '.array_to_string($teachers_parsed, CourseManager::USER_SEPARATOR); |
||
| 1267 | } |
||
| 1268 | $this->assign('teachers', $teacher_data); |
||
| 1269 | } |
||
| 1270 | } |
||
| 1271 | } |
||
| 1272 | |||
| 1273 | /** |
||
| 1274 | * Show footer js template. |
||
| 1275 | */ |
||
| 1276 | public function show_footer_js_template() |
||
| 1277 | { |
||
| 1278 | $tpl = $this->get_template('layout/footer.js.tpl'); |
||
| 1279 | $this->display($tpl); |
||
| 1280 | } |
||
| 1281 | |||
| 1282 | /** |
||
| 1283 | * Sets the plugin content in a template variable |
||
| 1284 | * @param string $pluginRegion |
||
| 1285 | * @return null |
||
| 1286 | */ |
||
| 1287 | public function set_plugin_region($pluginRegion) |
||
| 1288 | { |
||
| 1289 | if (!empty($pluginRegion)) { |
||
| 1290 | $regionContent = $this->plugin->load_region($pluginRegion, $this, $this->force_plugin_load); |
||
| 1291 | |||
| 1292 | $pluginList = $this->plugin->get_installed_plugins(); |
||
| 1293 | View Code Duplication | foreach ($pluginList as $plugin_name) { |
|
| 1294 | |||
| 1295 | // The plugin_info variable is available inside the plugin index |
||
| 1296 | $pluginInfo = $this->plugin->getPluginInfo($plugin_name); |
||
| 1297 | |||
| 1298 | if (isset($pluginInfo['is_course_plugin']) && $pluginInfo['is_course_plugin']) { |
||
| 1299 | $courseInfo = api_get_course_info(); |
||
| 1300 | |||
| 1301 | if (!empty($courseInfo)) { |
||
| 1302 | if (isset($pluginInfo['obj']) && $pluginInfo['obj'] instanceof Plugin) { |
||
| 1303 | /** @var Plugin $plugin */ |
||
| 1304 | $plugin = $pluginInfo['obj']; |
||
| 1305 | $regionContent .= $plugin->renderRegion($pluginRegion); |
||
| 1306 | } |
||
| 1307 | } |
||
| 1308 | } else { |
||
| 1309 | continue; |
||
| 1310 | } |
||
| 1311 | } |
||
| 1312 | |||
| 1313 | if (!empty($regionContent)) { |
||
| 1314 | $this->assign('plugin_'.$pluginRegion, $regionContent); |
||
| 1315 | } else { |
||
| 1316 | $this->assign('plugin_'.$pluginRegion, null); |
||
| 1317 | } |
||
| 1318 | } |
||
| 1319 | return null; |
||
| 1320 | } |
||
| 1321 | |||
| 1322 | /** |
||
| 1323 | * @param string $template |
||
| 1324 | * @return string |
||
| 1325 | */ |
||
| 1326 | public function fetch($template = null) |
||
| 1327 | { |
||
| 1328 | $template = str_replace('.tpl', '.html.twig', $template); |
||
| 1329 | $template = \Chamilo\CoreBundle\Framework\Container::getTwig()->load($template); |
||
| 1330 | return $template->render(self::$params); |
||
| 1331 | } |
||
| 1332 | |||
| 1333 | /** |
||
| 1334 | * @param string $variable |
||
| 1335 | * @param mixed $value |
||
| 1336 | */ |
||
| 1337 | public function assign($variable, $value = '') |
||
| 1338 | { |
||
| 1339 | self::$params[$variable] = $value; |
||
| 1340 | } |
||
| 1341 | |||
| 1342 | /** |
||
| 1343 | * Adds a body class for login pages |
||
| 1344 | */ |
||
| 1345 | public function setLoginBodyClass() |
||
| 1346 | { |
||
| 1347 | $this->assign('login_class', 'section-login'); |
||
| 1348 | } |
||
| 1349 | |||
| 1350 | /** |
||
| 1351 | * The theme that will be used if the database is not working. |
||
| 1352 | * @return string |
||
| 1353 | */ |
||
| 1354 | public static function getThemeFallback() |
||
| 1355 | { |
||
| 1356 | $theme = api_get_configuration_value('theme_fallback'); |
||
| 1357 | if (empty($theme)) { |
||
| 1358 | $theme = 'chamilo'; |
||
| 1359 | } |
||
| 1360 | return $theme; |
||
| 1361 | } |
||
| 1362 | |||
| 1363 | /** |
||
| 1364 | * @param bool|true $setLoginForm |
||
| 1365 | */ |
||
| 1366 | public function setLoginForm($setLoginForm = true) |
||
| 1367 | { |
||
| 1368 | global $loginFailed; |
||
| 1369 | $userId = api_get_user_id(); |
||
| 1370 | if (!($userId) || api_is_anonymous($userId)) { |
||
| 1371 | // Only display if the user isn't logged in. |
||
| 1372 | $this->assign( |
||
| 1373 | 'login_language_form', |
||
| 1374 | api_display_language_form(true) |
||
| 1375 | ); |
||
| 1376 | if ($setLoginForm) { |
||
| 1377 | $this->assign('login_form', $this->displayLoginForm()); |
||
| 1378 | |||
| 1379 | if ($loginFailed) { |
||
| 1380 | $this->assign('login_failed', $this::handleLoginFailed()); |
||
| 1381 | } |
||
| 1382 | } |
||
| 1383 | } |
||
| 1384 | } |
||
| 1385 | |||
| 1386 | /** |
||
| 1387 | * @return string |
||
| 1388 | */ |
||
| 1389 | public function handleLoginFailed() |
||
| 1432 | |||
| 1433 | /** |
||
| 1434 | * @return string |
||
| 1435 | */ |
||
| 1436 | public function displayLoginForm() |
||
| 1515 | |||
| 1516 | /** |
||
| 1517 | * Set administrator variables |
||
| 1518 | */ |
||
| 1519 | private function setAdministratorParams() |
||
| 1530 | |||
| 1531 | /** |
||
| 1532 | * Manage specific HTTP headers security |
||
| 1533 | * @return void (prints headers directly) |
||
| 1534 | */ |
||
| 1535 | private function addHTTPSecurityHeaders() |
||
| 1536 | { |
||
| 1537 | // Implementation of HTTP headers security, as suggested and checked |
||
| 1538 | // by https://securityheaders.io/ |
||
| 1539 | // Enable these settings in configuration.php to use them on your site |
||
| 1540 | // Strict-Transport-Security |
||
| 1541 | $setting = api_get_configuration_value('security_strict_transport'); |
||
| 1542 | if (!empty($setting)) { |
||
| 1543 | header('Strict-Transport-Security: '.$setting); |
||
| 1544 | } |
||
| 1545 | // Content-Security-Policy |
||
| 1546 | $setting = api_get_configuration_value('security_content_policy'); |
||
| 1547 | if (!empty($setting)) { |
||
| 1548 | header('Content-Security-Policy: '.$setting); |
||
| 1549 | } |
||
| 1550 | $setting = api_get_configuration_value('security_content_policy_report_only'); |
||
| 1585 | |||
| 1586 | public static function getParams() |
||
| 1590 | } |
||
| 1591 |
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of
return,dieorexitstatements that have been added for debug purposes.In the above example, the last
return falsewill never be executed, because a return statement has already been met in every possible execution path.