123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744 |
- <?php
- require_once api_get_path(LIBRARY_PATH) . 'banner.lib.php';
- require_once api_get_path(LIBRARY_PATH) . 'symfony/Twig/Autoloader.php';
- class Template {
- var $style = 'default';
- var $preview_theme = null;
- var $theme;
- var $title = null;
- var $show_header;
- var $show_footer;
- var $help;
- var $menu_navigation = array();
- var $show_learnpath = false;
- var $plugin = null;
- var $course_id = null;
- var $user_is_logged_in = false;
- var $twig = null;
-
- var $load_plugins = false;
- var $params = array();
- function __construct($title = '', $show_header = true, $show_footer = true, $show_learnpath = false, $hide_global_chat = false, $load_plugins = true) {
-
- $this->title = $title;
- $this->show_learnpath = $show_learnpath;
- $this->hide_global_chat = $hide_global_chat;
- $this->load_plugins = $load_plugins;
-
- Twig_Autoloader::register();
- $template_paths = array(
- api_get_path(SYS_CODE_PATH) . 'template',
- api_get_path(SYS_PLUGIN_PATH)
- );
- $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);
-
- if (api_get_setting('server_type') == 'test') {
- $options = array(
-
- 'autoescape' => false,
- 'debug' => true,
- 'auto_reload' => true,
- 'optimizations' => 0,
- 'strict_variables' => false,
- );
- } else {
- $options = array(
- 'cache' => $cache_folder,
- 'autoescape' => false,
- 'debug' => false,
- 'auto_reload' => false,
- 'optimizations' => -1,
- 'strict_variables' => false
- );
- }
- $this->twig = new Twig_Environment($loader, $options);
- $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('format_date', new Twig_Filter_Function('Template::format_date'));
-
-
- $this->set_system_parameters();
-
- $this->set_user_parameters();
-
- $this->set_course_parameters();
-
- $this->set_footer($show_footer);
- $this->set_header($show_header);
- $this->set_header_parameters();
- $this->set_footer_parameters();
- $this->assign('style', $this->style);
-
- if ($this->show_header) {
- if ($this->load_plugins) {
- $this->plugin = new AppPlugin();
-
- $plugin_regions = $this->plugin->get_plugin_regions();
- foreach ($plugin_regions as $region) {
- $this->set_plugin_region($region);
- }
-
- global $course_plugin;
- if (isset($course_plugin) && !empty($course_plugin) && !empty($this->course_id)) {
-
- $this->plugin->load_plugin_lang_variables($course_plugin);
- }
- }
- }
- }
-
- public static function get_icon_path($image, $size = ICON_SIZE_SMALL) {
- return Display:: return_icon($image, '', array(), $size, false, true);
- }
- public static function format_date($timestamp, $format = null) {
- return api_format_date($timestamp, $format);
- }
-
-
- 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;
- }
- function set_help($help_input = null) {
- if (!empty($help_input)) {
- $help = $help_input;
- } else {
- $help = $this->help;
- }
- $help_content = '';
- if (api_get_setting('enable_help_link') == 'true') {
- if (!empty($help)) {
- $help = Security::remove_XSS($help);
- $help_content = '<li class="help">';
- $help_content .= '<a href="' . api_get_path(WEB_CODE_PATH) . 'help/help.php?open=' . $help . '&height=400&width=600" class="ajax" title="' . get_lang('Help') . '">';
- $help_content .= '<img src="' . api_get_path(WEB_IMG_PATH) . 'help.large.png" alt="' . get_lang('Help') . '" title="' . get_lang('Help') . '" />';
- $help_content .= '</a></li>';
- }
- }
- $this->assign('help_content', $help_content);
- }
-
- function set_actions($actions) {
- $action_string = '';
- if (!empty($actions)) {
- foreach ($actions as $action) {
- $action_string .= $action;
- }
- }
- $this->assign('actions', $actions);
- }
-
- function display_one_col_template() {
- $tpl = $this->get_template('layout/layout_1_col.tpl');
- $this->display($tpl);
- }
-
- function display_two_col_template() {
- $tpl = $this->get_template('layout/layout_2_col.tpl');
- $this->display($tpl);
- }
-
- function display_blank_template() {
- $tpl = $this->get_template('layout/blank.tpl');
- $this->display($tpl);
- }
-
- function display_no_layout_template() {
- $tpl = $this->get_template('layout/no_layout.tpl');
- $this->display($tpl);
- }
-
- function set_footer($status) {
- $this->show_footer = $status;
- $this->assign('show_footer', $status);
- }
-
- function set_header($status) {
- $this->show_header = $status;
- $this->assign('show_header', $status);
-
- $show_admin_toolbar = api_get_setting('show_admin_toolbar');
- $show_toolbar = 0;
- switch ($show_admin_toolbar) {
- case 'do_not_show':
- break;
- case 'show_to_admin':
- if (api_is_platform_admin()) {
- $show_toolbar = 1;
- }
- break;
- case 'show_to_admin_and_teachers':
- if (api_is_platform_admin() || api_is_allowed_to_edit()) {
- $show_toolbar = 1;
- }
- break;
- case 'show_to_all':
- $show_toolbar = 1;
- break;
- }
- $this->assign('show_toolbar', $show_toolbar);
-
- $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') {
-
- $show_course_shortcut = CourseHome::show_navigation_tool_shortcuts();
- }
- if (api_get_setting('show_navigation_menu') != 'false') {
-
- $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);
- }
- function get_template($name) {
- return $this->style . '/' . $name;
- }
-
- private function set_course_parameters() {
-
- $course_id = api_get_course_int_id();
- $this->course_id = $course_id;
- }
-
- 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();
- $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;
- }
-
- $this->assign('_u', $user_info);
- }
-
- private function set_system_parameters() {
- global $_configuration;
-
- $_p = array('web' => api_get_path(WEB_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_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),
- );
- $this->assign('_p', $_p);
-
- $_s = array(
- 'software_name' => $_configuration['software_name'],
- 'system_version' => $_configuration['system_version'],
- 'site_name' => api_get_setting('siteName'),
- 'institution' => api_get_setting('Institution')
- );
- $this->assign('_s', $_s);
- }
-
- function set_css_files() {
- global $disable_js_and_css_files;
- $css = array();
-
-
- $this->theme = api_get_visual_theme();
- if (!empty($this->preview_theme)) {
- $this->theme = $this->preview_theme;
- }
-
- $css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH).'base.css');
-
- $css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH).$this->theme.'/default.css');
- $css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH).'bootstrap-responsive.css');
- $css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH).'responsive.css');
-
-
- $css[] = api_get_path(WEB_LIBRARY_PATH) . 'javascript/thickbox.css';
- $css[] = api_get_path(WEB_LIBRARY_PATH) . 'javascript/chosen/chosen.css';
-
- if ($this->show_learnpath) {
- $css[] = api_get_path(WEB_CSS_PATH) . $this->theme . '/learnpath.css';
- $css[] = api_get_path(WEB_CSS_PATH) . $this->theme . '/scorm.css';
- }
- if (api_is_global_chat_enabled()) {
- $css[] = api_get_path(WEB_LIBRARY_PATH) . 'javascript/chat/css/chat.css';
- }
-
- $css_file_to_string = null;
- foreach ($css as $file) {
- $css_file_to_string .= api_get_css($file);
- }
-
-
- if (SHOW_TEXT_NEAR_ICONS == true) {
-
- $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_file_to_string', $css_file_to_string);
-
- $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 = return_logo($this->theme);
- $this->assign('logo', $logo);
- }
-
- function set_js_files() {
- global $disable_js_and_css_files, $htmlHeadXtra;
-
-
- $js_files = array(
- 'modernizr.js',
- 'jquery.min.js',
- 'chosen/chosen.jquery.min.js',
- 'thickbox.js',
- 'bootstrap/bootstrap.js',
- );
-
- if (api_is_global_chat_enabled()) {
-
- 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';
- }
- if (api_get_setting('include_asciimathml_script') == 'true') {
- $js_files[] = 'asciimath/ASCIIMathML.js';
- }
-
- $js_file_to_string = null;
-
- foreach ($js_files as $js_file) {
- $js_file_to_string .= api_get_js($js_file);
- }
-
-
- 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);
-
-
- $extra_headers = api_get_jquery_ui_js();
-
- if (isset($htmlHeadXtra) && $htmlHeadXtra) {
- foreach ($htmlHeadXtra as & $this_html_head) {
- $extra_headers .= $this_html_head . "\n";
- }
- }
- $this->assign('extra_headers', $extra_headers);
- }
- }
-
- private function set_header_parameters() {
- global $httpHeadXtra, $_course, $interbreadcrumb, $language_file, $noPHP_SELF, $_configuration, $this_section;
- $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', Security::remove_XSS(Display::return_icon('online.png')));
- $this->assign('offline_button', Security::remove_XSS(Display::return_icon('offline.png')));
-
- $this->assign('document_language', api_get_language_isocode());
- $course_title = $_course['name'];
- $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);
-
-
- $this->set_css_files();
- $this->set_js_files();
-
-
-
- $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);
- $favico = '<link rel="shortcut icon" href="' . api_get_path(WEB_PATH) . 'favicon.ico" type="image/x-icon" />';
- if (isset($_configuration['multiple_access_urls']) && $_configuration['multiple_access_urls']) {
- $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 = replace_dangerous_char($url);
- $clean_url = str_replace('/', '-', $clean_url);
- $clean_url .= '/';
- $homep = api_get_path(REL_PATH) . 'home/' . $clean_url;
- $icon_real_homep = api_get_path(SYS_PATH) . 'home/' . $clean_url;
-
- 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->set_help();
-
- $bug_notification_link = '';
- 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">
- <img src="' . api_get_path(WEB_IMG_PATH) . 'bug.large.png" style="vertical-align: middle;" alt="' . get_lang('ReportABug') . '" title="' . get_lang('ReportABug') . '"/></a>
- </li>';
- }
- $this->assign('bug_notification_link', $bug_notification_link);
- $notification = return_notification_menu();
- $this->assign('notification_menu', $notification);
-
-
-
-
- $this->assign('logout_link', api_get_path(WEB_PATH).'index.php?logout=logout&&uid='.api_get_user_id());
-
-
- if (api_get_setting('allow_social_tool') == 'true') {
- $profile_link = '<a href="'.api_get_path(WEB_CODE_PATH).'social/home.php">'.get_lang('Profile').'</a>';
- } else {
- $profile_link = '<a href="'.api_get_path(WEB_CODE_PATH).'auth/profile.php">'.get_lang('Profile').'</a>';
- }
- $this->assign('profile_link', $profile_link);
-
-
- $message_link = null;
- if (api_get_setting('allow_message_tool') == 'true') {
- $message_link = '<a href="'.api_get_path(WEB_CODE_PATH).'messages/inbox.php">'.get_lang('Inbox').'</a>';
- }
- $this->assign('message_link', $message_link);
-
- $institution = api_get_setting('Institution');
- $portal_name = empty($institution) ? api_get_setting('siteName') : $institution;
-
- $this->assign('portal_name', $portal_name);
-
- $menu = return_menu();
- $this->assign('menu', $menu);
-
-
- $breadcrumb = return_breadcrumb($interbreadcrumb, $language_file, $nameTools);
- $this->assign('breadcrumb', $breadcrumb);
-
- $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 ($this->show_header == 1) {
- header('Content-Type: text/html; charset=' . api_get_system_encoding());
- header('X-Powered-By: ' . $_configuration['software_name'] . ' ' . substr($_configuration['system_version'], 0, 1));
- }
- }
-
- private function set_footer_parameters() {
- global $_configuration;
-
-
- if (api_get_setting('show_administrator_data') == 'true') {
-
- $administrator_data = get_lang('Manager') . ' : ' . Display::encrypted_mailto_link(api_get_setting('emailAdministrator'), api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname')));
- $this->assign('administrator_name', $administrator_data);
- }
-
- if (!api_is_platform_admin()) {
- $extra_footer = trim(api_get_setting('footer_extra_content'));
- if (!empty($extra_footer)) {
- $this->assign('footer_extra_content', $extra_footer);
- }
- }
-
- if (api_get_setting('show_tutor_data') == 'true') {
-
- $id_course = api_get_course_id();
- $id_session = api_get_session_id();
- if (isset($id_course) && $id_course != -1) {
- $tutor_data = '';
- if ($id_session != 0) {
- $coachs_email = CourseManager::get_email_of_tutor_to_session($id_session, $id_course);
- $email_link = array();
- foreach ($coachs_email as $coach) {
- $email_link[] = Display::encrypted_mailto_link($coach['email'], $coach['complete_name']);
- }
- if (count($coachs_email) > 1) {
- $tutor_data .= get_lang('Coachs') . ' : ';
- $tutor_data .= array_to_string($email_link, CourseManager::USER_SEPARATOR);
- } elseif (count($coachs_email) == 1) {
- $tutor_data .= get_lang('Coach') . ' : ';
- $tutor_data .= array_to_string($email_link, CourseManager::USER_SEPARATOR);
- } elseif (count($coachs_email) == 0) {
- $tutor_data .= '';
- }
- }
- $this->assign('session_teachers', $tutor_data);
- }
- }
- if (api_get_setting('show_teacher_data') == 'true') {
-
- $id_course = api_get_course_id();
- if (isset($id_course) && $id_course != -1) {
- $teacher_data = '';
- $mail = CourseManager::get_emails_of_tutors_to_course($id_course);
- if (!empty($mail)) {
- $teachers_parsed = array();
- foreach ($mail as $value) {
- foreach ($value as $email => $name) {
- $teachers_parsed[] = Display::encrypted_mailto_link($email, $name);
- }
- }
- $label = get_lang('Teacher');
- if (count($mail) > 1) {
- $label = get_lang('Teachers');
- }
- $teacher_data .= $label . ' : ' . array_to_string($teachers_parsed, CourseManager::USER_SEPARATOR);
- }
- $this->assign('teachers', $teacher_data);
- }
- }
-
- }
- function show_header_template() {
- $tpl = $this->get_template('layout/show_header.tpl');
- $this->display($tpl);
- }
- function show_footer_template() {
- $tpl = $this->get_template('layout/show_footer.tpl');
- $this->display($tpl);
- }
-
- function set_plugin_region($plugin_region) {
- if (!empty($plugin_region)) {
- $region_content = $this->plugin->load_region($plugin_region, $this, $this->force_plugin_load);
- if (!empty($region_content)) {
- $this->assign('plugin_' . $plugin_region, $region_content);
- } else {
- $this->assign('plugin_' . $plugin_region, null);
- }
- }
- return null;
- }
- public function fetch($template = null) {
- $template = $this->twig->loadTemplate($template);
- return $template->render($this->params);
- }
- public function assign($tpl_var, $value = null) {
- $this->params[$tpl_var] = $value;
- }
- public function display($template) {
- echo $this->twig->render($template, $this->params);
- }
- }
|