Fixing home edition see BT#9280

1.9.x
Julio Montoya 10 years ago
parent daede739b6
commit 7820985bdd
  1. 51
      main/admin/configure_homepage.php
  2. 21
      main/inc/lib/main_api.lib.php
  3. 52
      main/inc/lib/userportal.lib.php

@ -143,6 +143,8 @@ if (!empty($_SESSION['user_language_choice'])) {
$lang = api_get_setting('platformLanguage');
}
$languageGet = isset($_GET['language']) ? Security::remove_XSS($_GET['language']) : $lang;
// Ensuring availability of main files in the corresponding language
if (api_is_multiple_url_enabled()) {
@ -195,6 +197,7 @@ foreach ($homef as $my_file) {
}
}
}
if (api_is_multiple_url_enabled()) {
$homep = $homep_new;
}
@ -233,22 +236,20 @@ if (!empty($action)) {
}
// Write
if (file_exists($homep.$topf.'_'.$lang.$ext)) {
if (is_writable($homep)) {
// Default
if (is_writable($homep.$topf.'_'.$lang.$ext)) {
$fp = fopen($homep.$topf.'_'.$lang.$ext, 'w');
fputs($fp, $home_top);
fclose($fp);
var_dump($_languages['name']);exit;
// Language
foreach ($_languages['name'] as $key => $value) {
$lang_name = $_languages['folder'][$key];
if (isset($_POST[$lang_name])) {
if (file_exists($homep.$topf.'_'.$lang_name.$ext)) {
if (is_writable($homep.$topf.'_'.$lang_name.$ext)) {
$fp = fopen($homep.$topf.'_'.$lang_name.$ext, 'w');
fputs($fp, $home_top);
fclose($fp);
}
}
$fp = fopen($homep.$topf.'_'.$lang_name.$ext, 'w');
fputs($fp, $home_top);
fclose($fp);
}
}
} else {
@ -275,7 +276,13 @@ var_dump($_languages['name']);exit;
if (EventsMail::check_if_using_class('portal_homepage_edited')) {
EventsDispatcher::events('portal_homepage_edited',array('about_user' => api_get_user_id()));
}
event_system(LOG_HOMEPAGE_CHANGED, 'edit_top', cut(strip_tags($home_top), 254), api_get_utc_datetime(), api_get_user_id());
event_system(
LOG_HOMEPAGE_CHANGED,
'edit_top',
cut(strip_tags($home_top), 254),
api_get_utc_datetime(),
api_get_user_id()
);
break;
case 'edit_notice':
// Filter
@ -549,7 +556,7 @@ var_dump($_languages['name']);exit;
} //end of switch($action)
if (empty($errorMsg)) {
header('Location: '.api_get_self());
header('Location: '.api_get_self().'?language='.$languageGet);
exit();
}
} else {
@ -899,14 +906,13 @@ switch ($action) {
$form->addElement('checkbox', 'all_langs', null, get_lang('ApplyAllLanguages'), array('id' => 'all_langs'));
$form->addElement('html','<table id="table_langs" style="margin-left:159px;"><tr>');
$i = 0;
foreach ($_languages['name'] as $key => $value) {
$i++;
$lang_name = $_languages['folder'][$key];
$html_langs = '<td width="300">';
$html_langs .= '<label><input type="checkbox" id="lang" name="'.$lang_name.'" />&nbsp;'.$lang_name.'<label/>';
$html_langs .= '</td>';
if ($i%5 == 0) {
if ($i % 5 == 0) {
$html_langs .= '</tr><tr>';
}
$form->addElement('html', $html_langs);
@ -979,15 +985,21 @@ switch ($action) {
}
$form->addElement('checkbox', 'all_langs', null, get_lang('ApplyAllLanguages'),array('id' => 'all_langs'));
$form->addElement('html','<table id="table_langs" style="margin-left:5px;"><tr>');
$i = 0;
$currentLanguage = api_get_interface_language();
$i = 0;
foreach ($_languages['name'] as $key => $value) {
$i++;
$lang_name = $_languages['folder'][$key];
$i++;
$checked = null;
if ($languageGet == $lang_name) {
$checked = "checked";
}
$html_langs = '<td width="300">';
$html_langs .= '<label><input type="checkbox" id="lang" name="'.$lang_name.'" />&nbsp;'.$lang_name.'<label/>';
$html_langs .= '<label><input type="checkbox" '.$checked.' id="lang" name="'.$lang_name.'" />&nbsp;'.$value.'<label/>';
$html_langs .= '</td>';
if ($i%5 == 0) {
if ($i % 5 == 0) {
$html_langs .= '</tr><tr>';
}
$form->addElement('html', $html_langs);
@ -1004,10 +1016,10 @@ switch ($action) {
<tr>
<td width="70%" valign="top">
<div class="actions">
<a href="<?php echo api_get_self(); ?>?action=edit_top">
<a href="<?php echo api_get_self(); ?>?action=edit_top&language=<?php echo $languageGet; ?>">
<?php Display::display_icon('edit.gif', get_lang('EditHomePage')); ?>
</a>
<a href="<?php echo api_get_self(); ?>?action=edit_top">
<a href="<?php echo api_get_self(); ?>?action=edit_top&language=<?php echo $languageGet; ?>">
<?php echo get_lang('EditHomePage'); ?>
</a>
</div>
@ -1135,7 +1147,6 @@ switch ($action) {
</td>
<td width="10%" valign="top"></td>
<td width="20%" rowspan="3" valign="top">
<div id="login_block" class="well sidebar-nav">
<?php echo api_display_language_form(); ?>
<form id="formLogin">

@ -3808,7 +3808,6 @@ function api_display_language_form($hide_if_no_choice = false) {
$html .= '<label style="display: none;" for="language_list">' . get_lang('Language') . '</label>';
$html .= '<select id="language_list" class="chzn-select" name="language_list" onchange="javascript: jumpMenu(\'parent\',this,0);">';
foreach ($original_languages as $key => $value) {
if ($folder[$key] == $user_selected_language) {
$option_end = ' selected="selected" >';
@ -6416,24 +6415,28 @@ function api_is_multiple_url_enabled() {
* Returns a md5 unique id
* @todo add more parameters
*/
function api_get_unique_id() {
$id = md5(time().uniqid().api_get_user_id().api_get_course_id().api_get_session_id());
return $id;
}
/**
* Get home path
* @return string
*/
function api_get_home_path() {
$home = 'home/';
if (api_get_multiple_access_url()) {
$access_url_id = api_get_current_access_url_id();
$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 .= '/';
$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 .= '/';
// if $clean_url == "localhost/" means that the multiple URL was not well configured we don't rename the $home variable
if ($clean_url != 'localhost/')
$home = 'home/'.$clean_url;
//if ($clean_url != 'localhost/') {
$home = 'home/' . $clean_url;
//}
}
return $home;
}

@ -8,17 +8,21 @@ use \ChamiloSession as Session;
*/
class IndexManager
{
//An instance of the template engine
public $tpl = false;
public $name = '';
public $home = '';
public $default_home = 'home/';
// An instance of the template engine
public $tpl = false;
public $name = '';
public $home = '';
public $default_home = 'home/';
/**
* Construct
* @param string $title
*/
public function __construct($title)
{
$this->tpl = new Template($title);
$this->home = api_get_home_path();
$this->user_id = api_get_user_id();
$this->home = api_get_home_path();
$this->user_id = api_get_user_id();
$this->load_directories_preview = false;
if (api_get_setting('show_documents_preview') == 'true') {
@ -39,9 +43,7 @@ class IndexManager
// Only display if the user isn't logged in.
$this->tpl->assign('login_language_form', api_display_language_form(true));
if ($setLoginForm) {
$this->tpl->assign('login_form', self::display_login_form());
if ($loginFailed) {
@ -246,20 +248,23 @@ class IndexManager
} else {
$user_selected_language = api_get_setting('platformLanguage');
}
if (!file_exists($this->home.'home_news_'.$user_selected_language.'.html')) {
if (file_exists($this->home.'home_top.html')) {
$home_top_temp = file($this->home.'home_top.html');
} else {
$home_top_temp = file($this->default_home.'home_top.html');
}
$home_top_temp = implode('', $home_top_temp);
} else {
if (file_exists($this->home.'home_top_'.$user_selected_language.'.html')) {
$home_top_temp = file_get_contents($this->home.'home_top_'.$user_selected_language.'.html');
} else {
$home_top_temp = file_get_contents($this->home.'home_top.html');
}
}
// Try language specific home
if (file_exists($this->home.'home_top_'.$user_selected_language.'.html')) {
$home_top_temp = file_get_contents($this->home.'home_top_'.$user_selected_language.'.html');
}
// Try default language home
if (empty($home_top_temp)) {
if (file_exists($this->home.'home_top.html')) {
$home_top_temp = file_get_contents($this->home.'home_top.html');
} else {
if (file_exists($this->default_home.'home_top.html')) {
$home_top_temp = file_get_contents($this->default_home . 'home_top.html');
}
}
}
if (trim($home_top_temp) == '' && api_is_platform_admin()) {
$home_top_temp = '<div class="welcome-mascot">' . get_lang('PortalHomepageDefaultIntroduction') . '</div>';
} else {
@ -268,6 +273,7 @@ class IndexManager
$open = str_replace('{rel_path}', api_get_path(REL_PATH), $home_top_temp);
$html = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
}
return $html;
}

Loading…
Cancel
Save