From ae8042dd6957ad2b3702bfa3018abb1dc8df8b8e Mon Sep 17 00:00:00 2001 From: Alex Aragon Date: Wed, 2 Mar 2016 15:38:29 -0500 Subject: [PATCH 1/3] add function return array menu for template BT#10657 --- main/inc/lib/banner.lib.php | 163 +++++++++++++++++++++++++++++++++- main/inc/lib/template.lib.php | 6 +- main/social/home.php | 2 + 3 files changed, 165 insertions(+), 6 deletions(-) diff --git a/main/inc/lib/banner.lib.php b/main/inc/lib/banner.lib.php index e19fd5cc5c..c5180da046 100755 --- a/main/inc/lib/banner.lib.php +++ b/main/inc/lib/banner.lib.php @@ -364,6 +364,8 @@ function return_navigation_array() // Custom tabs $customTabs = getCustomTabs(); + + if (!empty($customTabs)) { foreach ($customTabs as $tab) { if (api_get_setting($tab['variable'], $tab['subkey']) == 'true' && @@ -380,7 +382,8 @@ function return_navigation_array() } } } - + + return array( 'menu_navigation' => $menu_navigation, 'navigation' => $navigation, @@ -388,11 +391,158 @@ function return_navigation_array() ); } -function return_menu() +function menuArray() +{ + $mainNavigation = return_navigation_array(); + unset($mainNavigation['navigation']); + unset($mainNavigation['menu_navigation']); + //$navigation = $navigation['navigation']; + // Get active language + $lang = api_get_setting('platformLanguage'); + if (!empty($_SESSION['user_language_choice'])) { + $lang = $_SESSION['user_language_choice']; + } elseif (!empty($_SESSION['_user']['language'])) { + $lang = $_SESSION['_user']['language']; + } + // Preparing home folder for multiple urls + if (api_get_multiple_access_url()) { + $access_url_id = api_get_current_access_url_id(); + if ($access_url_id != -1) { + // If not a dead URL + $urlInfo = api_get_access_url($access_url_id); + $url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $urlInfo['url'])); + $cleanUrl = api_replace_dangerous_char($url); + $cleanUrl = str_replace('/', '-', $cleanUrl); + $cleanUrl .= '/'; + $homepath = api_get_path(SYS_APP_PATH).'home/'.$cleanUrl; //homep for Home Path + //we create the new dir for the new sites + if (!is_dir($homepath)) { + mkdir($homepath, api_get_permissions_for_new_directories()); + } + } + } else { + $homepath = api_get_path(SYS_APP_PATH).'home/'; + } + $ext = '.html'; + $menuTabs = 'home_tabs'; + $menuTabsLoggedIn = 'home_tabs_logged_in'; + $pageContent = ''; + // Get the extra page content, containing the links to add to the tabs + if (is_file($homepath.$menuTabs.'_'.$lang.$ext) && is_readable($homepath.$menuTabs.'_'.$lang.$ext)) { + $pageContent = @(string) file_get_contents($homepath . $menuTabs . '_' . $lang . $ext); + } elseif (is_file($homepath.$menuTabs.$lang.$ext) && is_readable($homepath.$menuTabs.$lang.$ext)) { + $pageContent = @(string) file_get_contents($homepath . $menuTabs . $lang . $ext); + } else { + //$errorMsg = get_lang('HomePageFilesNotReadable'); + } + // Sanitize page content + $pageContent = api_to_system_encoding($pageContent, api_detect_encoding(strip_tags($pageContent))); + $open = str_replace('{rel_path}',api_get_path(REL_PATH), $pageContent); + $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open))); + // Get the extra page content, containing the links to add to the tabs + // that are only for users already logged in + $openMenuTabsLoggedIn = ''; + if (api_get_user_id() && !api_is_anonymous()) { + if (is_file($homepath . $menuTabsLoggedIn . '_' . $lang . $ext) && is_readable($homepath . $menuTabsLoggedIn . '_' . $lang . $ext)) { + $pageContent = @(string) file_get_contents($homepath . $menuTabsLoggedIn . '_' . $lang . $ext); + $pageContent = str_replace('::private', '', $pageContent); + } elseif (is_file($homepath . $menuTabsLoggedIn . $lang . $ext) && is_readable($homepath . $menuTabsLoggedIn . $lang . $ext)) { + $pageContent = @(string) file_get_contents($homepath . $menuTabsLoggedIn . $lang . $ext); + $pageContent = str_replace('::private', '', $pageContent); + } else { + //$errorMsg = get_lang('HomePageFilesNotReadable'); + } + + $pageContent = api_to_system_encoding($pageContent, api_detect_encoding(strip_tags($pageContent))); + $openMenuTabsLoggedIn = str_replace('{rel_path}',api_get_path(REL_PATH), $pageContent); + $openMenuTabsLoggedIn = api_to_system_encoding($openMenuTabsLoggedIn, api_detect_encoding(strip_tags($openMenuTabsLoggedIn))); + } + if (!empty($open) OR !empty($openMenuTabsLoggedIn)) { + if (strpos($open.$openMenuTabsLoggedIn, 'show_menu') === false) { + if (api_is_anonymous()) { + $mainNavigation['possible_tabs'][SECTION_CAMPUS] = null; + } + } else { + if (api_get_user_id() && !api_is_anonymous()) { + $list = split("\n", $openMenuTabsLoggedIn); + foreach ($list as $link) { + $matches = array(); + $match = preg_match('$href="([^"]*)" target="([^"]*)">([^<]*)$', $link, $matches); + if ($match) { + $mainNavigation['possible_tabs'][$matches[3]] = array( + 'url' => $matches[1], + 'target' => $matches[2], + 'title' => $matches[3], + 'key' => 'page-' . str_replace(' ', '-', strtolower($matches[3])) + ); + } + } + + } else { + + $list = split("\n", $open); + foreach ($list as $link) { + $matches = array(); + $match = preg_match('$href="([^"]*)" target="([^"]*)">([^<]*)$', $link, $matches); + if ($match) { + $mainNavigation['possible_tabs'][$matches[3]] = array( + 'url' => $matches[1], + 'target' => $matches[2], + 'title' => $matches[3], + 'key' => 'page-' . str_replace(' ', '-', strtolower($matches[3])) + ); + } + } + } + } + } + + if (count($mainNavigation['possible_tabs']) > 0) { + //$pre_lis = ''; + $activeSection = ''; + foreach ($mainNavigation['possible_tabs'] as $section => $navigation_info) { + + $key = (!empty($navigation_info['key'])?'tab-'.$navigation_info['key']:''); + + if (isset($GLOBALS['this_section'])) { + $tempSection = $section; + if ($section == 'social') { + $tempSection = 'social-network'; + } + if ($tempSection == $GLOBALS['this_section']) { + $activeSection = $section; + } + // If we're on the index page and a specific extra link has been + // loaded + if ($GLOBALS['this_section'] == SECTION_CAMPUS) { + if (!empty($_GET['include'])) { + $name = str_replace(' ', '-', strtolower($navigation_info['title'])) . '_' . $lang . $ext; + if ($_GET['include'] == $name) { + $activeSection = $section; + } + } + } + } else { + $current = ''; + } + $mainNavigation['possible_tabs'][$section]['current'] = ''; + } + if (!empty($activeSection)) { + $mainNavigation['possible_tabs'][$activeSection]['current'] = 'active'; + } + + } + unset($mainNavigation['possible_tabs']['myprofile']); + + return $mainNavigation['possible_tabs']; +} + + +/* function return_menu() { $navigation = return_navigation_array(); $navigation = $navigation['navigation']; - + // Displaying the tabs $lang = api_get_setting('platformLanguage'); @@ -473,9 +623,11 @@ function return_menu() } } } - + + if (count($navigation) > 0 || !empty($lis)) { $pre_lis = ''; + foreach ($navigation as $section => $navigation_info) { $key = (!empty($navigation_info['key'])?'tab-'.$navigation_info['key']:''); if (isset($GLOBALS['this_section'])) { @@ -487,6 +639,7 @@ function return_menu() $pre_lis .= ''.$navigation_info['title'].''; } } + $lis = $pre_lis.$lis; } @@ -494,8 +647,10 @@ function return_menu() if (!empty($lis)) { $menu .= $lis; } + return $menu; } +*/ function return_breadcrumb($interbreadcrumb, $language_file, $nameTools) { diff --git a/main/inc/lib/template.lib.php b/main/inc/lib/template.lib.php index 7be6538769..03019d681d 100755 --- a/main/inc/lib/template.lib.php +++ b/main/inc/lib/template.lib.php @@ -930,9 +930,11 @@ class Template $portal_name = empty($institution) ? api_get_setting('siteName') : $institution; $this->assign('portal_name', $portal_name); - + + //Menu - $menu = return_menu(); + $menu = menuArray(); + $this->assign('menu', $menu); // Setting notifications diff --git a/main/social/home.php b/main/social/home.php index 19bff55e13..115e4235a6 100755 --- a/main/social/home.php +++ b/main/social/home.php @@ -77,6 +77,7 @@ if (api_get_setting('profile', 'picture') == 'true') { //Block Menu $social_menu_block = SocialManager::show_social_menu('home'); + $social_search_block = Display::panel( UserManager::get_search_form(''), get_lang("SearchUsers") @@ -208,6 +209,7 @@ if (count($sessionList) > 0) { $social_group_block = Display::panelCollapse(get_lang('Group'), $social_group_block, 'sm-groups', null, 'grups-acordion', 'groups-collapse'); $tpl = new Template(get_lang('SocialNetwork')); + SocialManager::setSocialUserBlock($tpl, api_get_user_id(), 'home'); $tpl->assign('social_menu_block', $social_menu_block); From 9b3549925078015512e921bd0c7b679537e12684 Mon Sep 17 00:00:00 2001 From: Alex Aragon Date: Wed, 2 Mar 2016 16:48:55 -0500 Subject: [PATCH 2/3] fix menu array navigation BT#10657 --- main/inc/lib/banner.lib.php | 24 ++++++++++++++---------- main/inc/lib/template.lib.php | 1 - main/template/default/layout/menu.tpl | 4 +++- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/main/inc/lib/banner.lib.php b/main/inc/lib/banner.lib.php index c5180da046..0a780fe0ae 100755 --- a/main/inc/lib/banner.lib.php +++ b/main/inc/lib/banner.lib.php @@ -394,16 +394,19 @@ function return_navigation_array() function menuArray() { $mainNavigation = return_navigation_array(); - unset($mainNavigation['navigation']); + unset($mainNavigation['possible_tabs']); unset($mainNavigation['menu_navigation']); //$navigation = $navigation['navigation']; // Get active language $lang = api_get_setting('platformLanguage'); if (!empty($_SESSION['user_language_choice'])) { $lang = $_SESSION['user_language_choice']; + } elseif (!empty($_SESSION['_user']['language'])) { $lang = $_SESSION['_user']['language']; } + + // Preparing home folder for multiple urls if (api_get_multiple_access_url()) { $access_url_id = api_get_current_access_url_id(); @@ -415,6 +418,7 @@ function menuArray() $cleanUrl = str_replace('/', '-', $cleanUrl); $cleanUrl .= '/'; $homepath = api_get_path(SYS_APP_PATH).'home/'.$cleanUrl; //homep for Home Path + var_dump($homepath); //we create the new dir for the new sites if (!is_dir($homepath)) { mkdir($homepath, api_get_permissions_for_new_directories()); @@ -460,7 +464,7 @@ function menuArray() if (!empty($open) OR !empty($openMenuTabsLoggedIn)) { if (strpos($open.$openMenuTabsLoggedIn, 'show_menu') === false) { if (api_is_anonymous()) { - $mainNavigation['possible_tabs'][SECTION_CAMPUS] = null; + $mainNavigation['navigation'][SECTION_CAMPUS] = null; } } else { if (api_get_user_id() && !api_is_anonymous()) { @@ -469,7 +473,7 @@ function menuArray() $matches = array(); $match = preg_match('$href="([^"]*)" target="([^"]*)">([^<]*)$', $link, $matches); if ($match) { - $mainNavigation['possible_tabs'][$matches[3]] = array( + $mainNavigation['navigation'][$matches[3]] = array( 'url' => $matches[1], 'target' => $matches[2], 'title' => $matches[3], @@ -485,7 +489,7 @@ function menuArray() $matches = array(); $match = preg_match('$href="([^"]*)" target="([^"]*)">([^<]*)$', $link, $matches); if ($match) { - $mainNavigation['possible_tabs'][$matches[3]] = array( + $mainNavigation['navigation'][$matches[3]] = array( 'url' => $matches[1], 'target' => $matches[2], 'title' => $matches[3], @@ -497,10 +501,10 @@ function menuArray() } } - if (count($mainNavigation['possible_tabs']) > 0) { + if (count($mainNavigation['navigation']) > 0) { //$pre_lis = ''; $activeSection = ''; - foreach ($mainNavigation['possible_tabs'] as $section => $navigation_info) { + foreach ($mainNavigation['navigation'] as $section => $navigation_info) { $key = (!empty($navigation_info['key'])?'tab-'.$navigation_info['key']:''); @@ -525,16 +529,16 @@ function menuArray() } else { $current = ''; } - $mainNavigation['possible_tabs'][$section]['current'] = ''; + $mainNavigation['navigation'][$section]['current'] = ''; } if (!empty($activeSection)) { - $mainNavigation['possible_tabs'][$activeSection]['current'] = 'active'; + $mainNavigation['navigation'][$activeSection]['current'] = 'active'; } } - unset($mainNavigation['possible_tabs']['myprofile']); + unset($mainNavigation['navigation']['myprofile']); - return $mainNavigation['possible_tabs']; + return $mainNavigation['navigation']; } diff --git a/main/inc/lib/template.lib.php b/main/inc/lib/template.lib.php index 03019d681d..9b73c0b953 100755 --- a/main/inc/lib/template.lib.php +++ b/main/inc/lib/template.lib.php @@ -934,7 +934,6 @@ class Template //Menu $menu = menuArray(); - $this->assign('menu', $menu); // Setting notifications diff --git a/main/template/default/layout/menu.tpl b/main/template/default/layout/menu.tpl index 0f4e41389b..b22d0101ef 100755 --- a/main/template/default/layout/menu.tpl +++ b/main/template/default/layout/menu.tpl @@ -12,7 +12,9 @@