Allow private and public links (tabs) on navigation menu BT#7008

1.9.x
Cesar Perales 12 years ago
parent 97c9a04599
commit 2a3c26b5d9
  1. 75
      main/admin/configure_homepage.php
  2. 35
      main/inc/lib/banner.lib.php

@ -4,6 +4,42 @@
* Configure the portal homepage (manages multi-urls and languages)
* @package chamilo.admin
*/
/**
* Creates menu tabs for logged and anonymous users
*
* This function copies the file containing private a public tabs (home_tabs_logged_in_$language.html)
* in to the public tab template (home_tabs_$language.html) but without the private tabs.
* Private tabs are the ones including "?private" string in the end of the url, ex: http://google.com/?private
*
* @param string Name of the file been updated by the administration, ex: home_tabs_logged_in_($language).html
*/
function home_tabs($file_logged_in)
{
$file_logged_out = str_replace('_logged_in','', $file_logged_in);
//variables initialization
$data_logged_out = array();
$data_logged_in = array();
//we read the file with all links
$file = file($file_logged_in);
foreach ($file as $line) {
//not logged user only sees public links
if (!preg_match('/\?private/',$line)) {
$data_logged_out[] = $line;
}
//logged user only sees all links
$data_logged_in[] = $line;
}
//tabs file for logged out users
$fp = fopen($file_logged_out, 'w');
fputs($fp, implode("\n", $data_logged_out));
fclose($fp);
//tabs file for logged in users
$fp = fopen($file_logged_in, 'w');
fputs($fp, implode("\n", $data_logged_in));
fclose($fp);
}
/**
* Code
*/
@ -107,14 +143,15 @@ if (api_is_multiple_url_enabled()) {
$homep = api_get_path(SYS_PATH).'home/'; //homep for Home Path
}
$menuf = 'home_menu'; //menuf for Menu File
$newsf = 'home_news'; //newsf for News File
$topf = 'home_top'; //topf for Top File
$noticef = 'home_notice'; //noticef for Notice File
$menutabs= 'home_tabs'; //menutabs for tabs Menu
$menuf = 'home_menu'; //menuf for Menu File
$newsf = 'home_news'; //newsf for News File
$topf = 'home_top'; //topf for Top File
$noticef = 'home_notice'; //noticef for Notice File
$menutabs = 'home_tabs'; //menutabs for tabs Menu
$mtloggedin= 'home_tabs_logged_in'; //menutabs for tabs Menu
$ext = '.html'; //ext for HTML Extension - when used frequently, variables are
// faster than hardcoded strings
$homef = array($menuf, $newsf, $topf, $noticef, $menutabs);
$homef = array($menuf, $newsf, $topf, $noticef, $menutabs, $mtloggedin);
// If language-specific file does not exist, create it by copying default file
foreach ($homef as $my_file) {
@ -328,7 +365,7 @@ if (!empty($action)) {
} elseif (!empty($link_url) && !strstr($link_url, '://')) {
$link_url='http://'.$link_url;
}
$menuf = ($action == 'insert_tabs' || $action == 'edit_tabs')? $menutabs : $menuf;
$menuf = ($action == 'insert_tabs' || $action == 'edit_tabs')? $mtloggedin : $menuf;
if (!is_writable($homep.$menuf.'_'.$lang.$ext)) {
$errorMsg = get_lang('HomePageFilesNotWritable');
} elseif (empty($link_name)) {
@ -375,8 +412,10 @@ if (!empty($action)) {
if ($fp) {
if (empty($link_html)) {
fputs($fp, get_lang('MyTextHere'));
home_tabs($homep.$filename);
} else {
fputs($fp, $link_html);
home_tabs($homep.$filename);
}
fclose($fp);
}
@ -387,6 +426,7 @@ if (!empty($action)) {
$fp = @fopen($homep.$filename, 'w');
if ($fp) {
fputs($fp, $link_html);
home_tabs($homep.$filename);
fclose($fp);
}
}
@ -421,6 +461,7 @@ if (!empty($action)) {
if (is_writable($homep.$menuf.'_'.$lang.$ext)) {
$fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w');
fputs($fp, $home_menu);
home_tabs($homep.$menuf.'_'.$lang.$ext);
fclose($fp);
if ($_POST['all_langs']) {
foreach ($_languages['name'] as $key => $value) {
@ -429,6 +470,7 @@ if (!empty($action)) {
if (is_writable($homep.$menuf.'_'.$lang_name.$ext)) {
$fp = fopen($homep.$menuf.'_'.$lang_name.$ext, 'w');
fputs($fp, $home_menu);
home_tabs($homep.$menuf.'_'.$lang_name.$ext);
fclose($fp);
}
}
@ -438,6 +480,7 @@ if (!empty($action)) {
if (is_writable($homep.$menuf.$ext)) {
$fpo = fopen($homep.$menuf.$ext, 'w');
fputs($fpo, $home_menu);
home_tabs($homep.$menuf.$ext);
fclose($fpo);
}
}
@ -448,6 +491,7 @@ if (!empty($action)) {
//File does not exist
$fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w');
fputs($fp, $home_menu);
home_tabs($homep.$menuf.'_'.$lang.$ext);
fclose($fp);
if ($_POST['all_langs']) {
foreach ($_languages['name'] as $key => $value) {
@ -455,6 +499,7 @@ if (!empty($action)) {
if (file_exists($homep.$menuf.'_'.$lang_name.$ext)) {
$fp = fopen($homep.$menuf.'_'.$lang_name.$ext, 'w');
fputs($fp, $home_menu);
home_tabs($homep.$menuf.'_'.$lang_name.$ext);
fclose($fp);
}
}
@ -481,7 +526,7 @@ if (!empty($action)) {
// A link is deleted by getting the file into an array, removing the
// link and re-writing the array to the file
$link_index = intval($_GET['link_index']);
$menuf = ($action == 'delete_tabs')? $menutabs : $menuf;
$menuf = ($action == 'delete_tabs')? $mtloggedin : $menuf;
$home_menu = @file($homep.$menuf.'_'.$lang.$ext);
if (empty($home_menu)) {
$home_menu = array();
@ -498,11 +543,13 @@ if (!empty($action)) {
$fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w');
fputs($fp, $home_menu);
home_tabs($homep.$menuf.'_'.$lang.$ext);
fclose($fp);
if (file_exists($homep.$menuf.$ext)) {
if (is_writable($homep.$menuf.$ext)) {
$fpo = fopen($homep.$menuf.$ext,'w');
fputs($fpo, $home_menu);
home_tabs($homep.$menuf.$ext);
fclose($fpo);
}
}
@ -554,7 +601,7 @@ if (!empty($action)) {
case 'insert_link':
// This request is the preparation for the addition of an item in home_menu
$home_menu = '';
$menuf = ($action == 'edit_tabs')? $menutabs : $menuf;
$menuf = ($action == 'edit_tabs')? $mtloggedin : $menuf;
if (is_file($homep.$menuf.'_'.$lang.$ext) && is_readable($homep.$menuf.'_'.$lang.$ext)) {
$home_menu = @file($homep.$menuf.'_'.$lang.$ext);
} elseif(is_file($homep.$menuf.$lang.$ext) && is_readable($homep.$menuf.$lang.$ext)) {
@ -596,7 +643,7 @@ if (!empty($action)) {
case 'edit_link':
// This request is the preparation for the edition of the links array
$home_menu = '';
$menuf = ($action == 'edit_tabs')? $menutabs : $menuf;
$menuf = ($action == 'edit_tabs')? $mtloggedin : $menuf;
if (is_file($homep.$menuf.'_'.$lang.$ext) && is_readable($homep.$menuf.'_'.$lang.$ext)) {
$home_menu = @file($homep.$menuf.'_'.$lang.$ext);
} elseif(is_file($homep.$menuf.$lang.$ext) && is_readable($homep.$menuf.$lang.$ext)) {
@ -947,10 +994,10 @@ switch ($action) {
// Add new page
$home_menu = '';
if (file_exists($homep.$menutabs.'_'.$lang.$ext)) {
$home_menu = @file($homep.$menutabs.'_'.$lang.$ext);
if (file_exists($homep.$mtloggedin.'_'.$lang.$ext)) {
$home_menu = @file($homep.$mtloggedin.'_'.$lang.$ext);
} else {
$home_menu = @file($homep.$menutabs.$ext);
$home_menu = @file($homep.$mtloggedin.$ext);
}
if (empty($home_menu)) {
$home_menu = array();
@ -1067,4 +1114,4 @@ switch ($action) {
<?php
break;
}
Display::display_footer();
Display::display_footer();

@ -368,9 +368,10 @@ function return_menu() {
$homep = api_get_path(SYS_PATH).'home/';
}
$ext = '.html';
$menutabs = 'home_tabs';
$home_top = '';
$ext = '.html';
$menutabs = 'home_tabs';
$mtloggedin = 'home_tabs_logged_in';
$home_top = '';
if (is_file($homep.$menutabs.'_'.$lang.$ext) && is_readable($homep.$menutabs.'_'.$lang.$ext)) {
$home_top = @(string)file_get_contents($homep.$menutabs.'_'.$lang.$ext);
@ -385,16 +386,38 @@ function return_menu() {
$open = str_replace('{rel_path}',api_get_path(REL_PATH), $home_top);
$open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
$open_mtloggedin = '';
if (api_get_user_id() && !api_is_anonymous()) {
if (is_file($homep.$mtloggedin.'_'.$lang.$ext) && is_readable($homep.$mtloggedin.'_'.$lang.$ext)) {
$home_top = @(string)file_get_contents($homep.$mtloggedin.'_'.$lang.$ext);
} elseif (is_file($homep.$mtloggedin.$lang.$ext) && is_readable($homep.$mtloggedin.$lang.$ext)) {
$home_top = @(string)file_get_contents($homep.$mtloggedin.$lang.$ext);
} else {
//$errorMsg = get_lang('HomePageFilesNotReadable');
}
$home_top = api_to_system_encoding($home_top, api_detect_encoding(strip_tags($home_top)));
$open_mtloggedin = str_replace('{rel_path}',api_get_path(REL_PATH), $home_top);
$open_mtloggedin = api_to_system_encoding($open_mtloggedin, api_detect_encoding(strip_tags($open_mtloggedin)));
}
$lis = '';
if (!empty($open)) {
if (strpos($open, 'show_menu') === false) {
if (!empty($open) OR !empty($open_mtloggedin)) {
if (strpos($open.$open_mtloggedin, 'show_menu') === false) {
if (api_is_anonymous()) {
$navigation[SECTION_CAMPUS] = null;
}
} else {
//$lis .= Display::tag('li', $open);
$lis .= $open;
if (api_get_user_id() && !api_is_anonymous()) {
$lis .= $open_mtloggedin;
} else {
$lis .= $open;
}
}
}

Loading…
Cancel
Save