From c39a31ab9440d78352a175f562dbb0f111e48e25 Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Mon, 11 Jun 2018 10:22:17 -0500 Subject: [PATCH 1/2] Minor: Factorize favico setting in template.lib.php out of set_header_parameters() --- main/inc/lib/template.lib.php | 71 ++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 31 deletions(-) diff --git a/main/inc/lib/template.lib.php b/main/inc/lib/template.lib.php index 4a831d27a7..b660e84855 100755 --- a/main/inc/lib/template.lib.php +++ b/main/inc/lib/template.lib.php @@ -1421,37 +1421,7 @@ class Template $this->assign('text_direction', api_get_text_direction()); $this->assign('section_name', 'section-'.$this_section); - // Default root chamilo favicon - $favico = ''; - - //Added to verify if in the current Chamilo Theme exist a favicon - $favicoThemeUrl = api_get_path(SYS_CSS_PATH).$this->themeDir.'images/'; - - //If exist pick the current chamilo theme favicon - if (is_file($favicoThemeUrl.'favicon.ico')) { - $favico = ''; - } - - if (api_is_multiple_url_enabled()) { - $access_url_id = api_get_current_access_url_id(); - if ($access_url_id != -1) { - $url_info = api_get_access_url($access_url_id); - $url = api_remove_trailing_slash( - preg_replace('/https?:\/\//i', '', $url_info['url']) - ); - $clean_url = api_replace_dangerous_char($url); - $clean_url = str_replace('/', '-', $clean_url); - $clean_url .= '/'; - $homep = api_get_path(REL_PATH).'home/'.$clean_url; //homep for Home Path - $icon_real_homep = api_get_path(SYS_APP_PATH).'home/'.$clean_url; - //we create the new dir for the new sites - if (is_file($icon_real_homep.'favicon.ico')) { - $favico = ''; - } - } - } - - $this->assign('favico', $favico); + $this->assignFavIcon(); //Set a 'favico' var depending on CSS and stuff $this->setHelp(); //@todo move this in the template @@ -1806,4 +1776,43 @@ class Template } // end of HTTP headers security block } + /** + * Assign favicon to the 'favico' template variable + * @return bool Always return true because there is always at least one correct favicon.ico + */ + private function assignFavIcon() + { + // Default root chamilo favicon + $favico = ''; + + //Added to verify if in the current Chamilo Theme exist a favicon + $favicoThemeUrl = api_get_path(SYS_CSS_PATH).$this->themeDir.'images/'; + + //If exist pick the current chamilo theme favicon + if (is_file($favicoThemeUrl.'favicon.ico')) { + $favico = ''; + } + + if (api_is_multiple_url_enabled()) { + $access_url_id = api_get_current_access_url_id(); + if ($access_url_id != -1) { + $url_info = api_get_access_url($access_url_id); + $url = api_remove_trailing_slash( + preg_replace('/https?:\/\//i', '', $url_info['url']) + ); + $clean_url = api_replace_dangerous_char($url); + $clean_url = str_replace('/', '-', $clean_url); + $clean_url .= '/'; + $homep = api_get_path(REL_PATH).'home/'.$clean_url; //homep for Home Path + $icon_real_homep = api_get_path(SYS_APP_PATH).'home/'.$clean_url; + //we create the new dir for the new sites + if (is_file($icon_real_homep.'favicon.ico')) { + $favico = ''; + } + } + } + + $this->assign('favico', $favico); + return true; + } } From 9fe98454518cb1b6aa9c9308d0313cb67e9d96d5 Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Mon, 11 Jun 2018 10:40:03 -0500 Subject: [PATCH 2/2] Minor - Factorize assignBugNotification(), assignAccessibilityBlock() and assignSocialMeta() in template.lib.php to simplify code readability --- main/inc/lib/template.lib.php | 229 +++++++++++++++++++--------------- 1 file changed, 130 insertions(+), 99 deletions(-) diff --git a/main/inc/lib/template.lib.php b/main/inc/lib/template.lib.php index b660e84855..41a0b28c44 100755 --- a/main/inc/lib/template.lib.php +++ b/main/inc/lib/template.lib.php @@ -58,7 +58,7 @@ class Template * @param bool $hide_global_chat * @param bool $load_plugins * @param int $responseCode - * @param bool $sendHeaders send http headers or not + * @param bool $sendHeaders send http headers or not */ public function __construct( $title = '', @@ -947,7 +947,7 @@ class Template /** * Render the template. * - * @param string $template The template path + * @param string $template The template path * @param bool $clearFlashMessages Clear the $_SESSION variables for flash messages */ public function display($template, $clearFlashMessages = true) @@ -1421,66 +1421,12 @@ class Template $this->assign('text_direction', api_get_text_direction()); $this->assign('section_name', 'section-'.$this_section); - $this->assignFavIcon(); //Set a 'favico' var depending on CSS and stuff + $this->assignFavIcon(); //Set a 'favico' var for the template $this->setHelp(); - //@todo move this in the template - $rightFloatMenu = ''; - $iconBug = Display::return_icon( - 'bug.png', - get_lang('ReportABug'), - [], - ICON_SIZE_LARGE - ); - if (api_get_setting('show_link_bug_notification') == 'true' && $this->user_is_logged_in) { - $rightFloatMenu = ''; - } + $this->assignBugNotification(); //Prepare the 'bug_notification' var for the template - if (api_get_setting('show_link_ticket_notification') == 'true' && - $this->user_is_logged_in - ) { - // by default is project_id = 1 - $defaultProjectId = 1; - $allow = TicketManager::userIsAllowInProject(api_get_user_info(), $defaultProjectId); - if ($allow) { - $iconTicket = Display::return_icon( - 'help.png', - get_lang('Ticket'), - [], - ICON_SIZE_LARGE - ); - $courseInfo = api_get_course_info(); - $courseParams = ''; - if (!empty($courseInfo)) { - $courseParams = api_get_cidreq(); - } - $url = api_get_path(WEB_CODE_PATH). - 'ticket/tickets.php?project_id='.$defaultProjectId.'&'.$courseParams; - $rightFloatMenu .= ''; - } - } - - $this->assign('bug_notification', $rightFloatMenu); - - $resize = ''; - if (api_get_setting('accessibility_font_resize') == 'true') { - $resize .= '
'; - $resize .= '
'; - $resize .= ''; - $resize .= ''; - $resize .= ''; - $resize .= '
'; - $resize .= '
'; - } - $this->assign('accessibility', $resize); + $this->assignAccessibilityBlock(); //Prepare the 'accessibility' var for the template // Preparing values for the menu @@ -1574,46 +1520,7 @@ class Template } } - $socialMeta = ''; - $metaTitle = api_get_setting('meta_title'); - if (!empty($metaTitle)) { - $socialMeta .= ''."\n"; - $metaSite = api_get_setting('meta_twitter_site'); - if (!empty($metaSite)) { - $socialMeta .= ''."\n"; - $metaCreator = api_get_setting('meta_twitter_creator'); - if (!empty($metaCreator)) { - $socialMeta .= ''."\n"; - } - } - - // The user badge page emits its own meta tags, so if this is - // enabled, ignore the global ones - $userId = isset($_GET['user']) ? intval($_GET['user']) : 0; - $skillId = isset($_GET['skill']) ? intval($_GET['skill']) : 0; - - if (!$userId && !$skillId) { - // no combination of user and skill ID has been defined, - // so print the normal OpenGraph meta tags - $socialMeta .= ''."\n"; - $socialMeta .= ''."\n"; - - $metaDescription = api_get_setting('meta_description'); - if (!empty($metaDescription)) { - $socialMeta .= ''."\n"; - } - - $metaImage = api_get_setting('meta_image_path'); - if (!empty($metaImage)) { - if (is_file(api_get_path(SYS_PATH).$metaImage)) { - $path = api_get_path(WEB_PATH).$metaImage; - $socialMeta .= ''."\n"; - } - } - } - } - - $this->assign('social_meta', $socialMeta); + $this->assignSocialMeta(); } /** @@ -1776,6 +1683,7 @@ class Template } // end of HTTP headers security block } + /** * Assign favicon to the 'favico' template variable * @return bool Always return true because there is always at least one correct favicon.ico @@ -1815,4 +1723,127 @@ class Template $this->assign('favico', $favico); return true; } + + /** + * Assign HTML code to the 'bug_notification' template variable for the side tabs to report issues + * @return bool Always return true because there is always a string, even if empty + */ + function assignBugNotification() + { + //@todo move this in the template + $rightFloatMenu = ''; + $iconBug = Display::return_icon( + 'bug.png', + get_lang('ReportABug'), + [], + ICON_SIZE_LARGE + ); + if (api_get_setting('show_link_bug_notification') == 'true' && $this->user_is_logged_in) { + $rightFloatMenu = ''; + } + + if (api_get_setting('show_link_ticket_notification') == 'true' && + $this->user_is_logged_in + ) { + // by default is project_id = 1 + $defaultProjectId = 1; + $allow = TicketManager::userIsAllowInProject(api_get_user_info(), $defaultProjectId); + if ($allow) { + $iconTicket = Display::return_icon( + 'help.png', + get_lang('Ticket'), + [], + ICON_SIZE_LARGE + ); + $courseInfo = api_get_course_info(); + $courseParams = ''; + if (!empty($courseInfo)) { + $courseParams = api_get_cidreq(); + } + $url = api_get_path(WEB_CODE_PATH). + 'ticket/tickets.php?project_id='.$defaultProjectId.'&'.$courseParams; + $rightFloatMenu .= ''; + } + } + + $this->assign('bug_notification', $rightFloatMenu); + return true; + } + + /** + * Assign HTML code to the 'accessibility' template variable (usually shown above top menu) + * @return bool Always return true (even if empty string) + */ + private function assignAccessibilityBlock() + { + $resize = ''; + if (api_get_setting('accessibility_font_resize') == 'true') { + $resize .= '
'; + $resize .= '
'; + $resize .= ''; + $resize .= ''; + $resize .= ''; + $resize .= '
'; + $resize .= '
'; + } + $this->assign('accessibility', $resize); + return true; + } + + /** + * Assign HTML code to the 'social_meta' template variable (usually shown above top menu) + * @return bool Always return true (even if empty string) + */ + private function assignSocialMeta() + { + $socialMeta = ''; + $metaTitle = api_get_setting('meta_title'); + if (!empty($metaTitle)) { + $socialMeta .= ''."\n"; + $metaSite = api_get_setting('meta_twitter_site'); + if (!empty($metaSite)) { + $socialMeta .= ''."\n"; + $metaCreator = api_get_setting('meta_twitter_creator'); + if (!empty($metaCreator)) { + $socialMeta .= ''."\n"; + } + } + + // The user badge page emits its own meta tags, so if this is + // enabled, ignore the global ones + $userId = isset($_GET['user']) ? intval($_GET['user']) : 0; + $skillId = isset($_GET['skill']) ? intval($_GET['skill']) : 0; + + if (!$userId && !$skillId) { + // no combination of user and skill ID has been defined, + // so print the normal OpenGraph meta tags + $socialMeta .= ''."\n"; + $socialMeta .= ''."\n"; + + $metaDescription = api_get_setting('meta_description'); + if (!empty($metaDescription)) { + $socialMeta .= ''."\n"; + } + + $metaImage = api_get_setting('meta_image_path'); + if (!empty($metaImage)) { + if (is_file(api_get_path(SYS_PATH).$metaImage)) { + $path = api_get_path(WEB_PATH).$metaImage; + $socialMeta .= ''."\n"; + } + } + } + } + + $this->assign('social_meta', $socialMeta); + return true; + } }