Added Feature to customize the logo of each StyleSheet - Refs #8118

Conflicts:
	main/admin/settings.lib.php
ofaj
José Loguercio 10 years ago
parent 992bcacb0a
commit 2bbf99a834
  1. 72
      main/admin/settings.lib.php
  2. 31
      main/inc/lib/banner.lib.php

@ -362,6 +362,67 @@ function handle_stylesheets()
}
}
}
$logoForm = new FormValidator(
'logo_upload',
'post',
'settings.php?category=Stylesheets#tabs-2'
);
$logoForm->addHtml(Display::return_message(sprintf(get_lang('TheLogoMustBeSizeXAndFormatY'), '250 x 70', 'PNG'), 'info'));
$dir = api_get_path(SYS_PUBLIC_PATH).'css/themes/' . $selected . '/images/';
$url = api_get_path(WEB_CSS_PATH).'themes/' . $selected . '/images/';
$logoFileName = 'header-logo.png';
$newLogoFileName = 'header-logo-custom.png';
if (is_file($dir.$newLogoFileName)) {
$logoForm->addLabel(get_lang('CurrentLogo'), '<img id="header-logo-custom" src="'. $url . $newLogoFileName .'?'. time() . '">');
} else {
$logoForm->addLabel(get_lang('CurrentLogo'), '<img id="header-logo-custom" src="'. $url . $logoFileName .'?'. time() . '">');
}
$logoForm->addFile('new_logo', get_lang('UpdateLogo'));
$allowedFileTypes = ['png'];
if (isset($_POST['logo_reset'])) {
if (is_file($dir.$newLogoFileName)) {
unlink($dir.$newLogoFileName);
Display::display_normal_message(get_lang('ResetToTheOriginalLogo'));
echo '<script>'
. '$("#header-logo").attr("src","'.$url.$logoFileName.'");'
. '</script>';
}
} elseif (isset($_POST['logo_upload'])) {
$logoForm->addRule('new_logo', get_lang('InvalidExtension').' ('.implode(',', $allowedFileTypes).')', 'filetype', $allowedFileTypes);
$logoForm->addRule('new_logo', get_lang('ThisFieldIsRequired'), 'required');
if ($logoForm->validate()) {
$imageInfo = getimagesize($_FILES['new_logo']['tmp_name']);
$width = $imageInfo[0];
$height = $imageInfo[1];
if ($width <= 250 && $height <= 70 ) {
if (is_file($dir.$newLogoFileName)) {
unlink($dir.$newLogoFileName);
}
$status = move_uploaded_file($_FILES['new_logo']['tmp_name'], $dir.$newLogoFileName);
if ($status) {
Display::display_normal_message(get_lang('NewLogoUpdated'));
echo '<script>'
. '$("#header-logo").attr("src","'.$url.$newLogoFileName.'");'
. '</script>';
} else {
Display::display_error_message('Error - '.get_lang('UplNoFileUploaded'));
}
} else {
Display::display_error_message('Error - '.get_lang('InvalidImageDimensions'));
}
}
}
if ($is_style_changeable) {
$group = [
@ -385,6 +446,17 @@ function handle_stylesheets()
} else {
$form_change->display();
}
//Little hack to update the logo image in update form when submiting
if (isset($_POST['logo_reset'])) {
echo '<script>'
. '$("#header-logo-custom").attr("src","'.$url.$logoFileName.'");'
. '</script>';
} elseif (isset($_POST['logo_upload'])) {
echo '<script>'
. '$("#header-logo-custom").attr("src","'.$url.$newLogoFileName.'");'
. '</script>';
}
} else {
$form_change->freeze();
}

@ -152,33 +152,44 @@ function return_logo($theme)
$_course = api_get_course_info();
$html = '';
$logoBase = api_get_path(SYS_CSS_PATH).'themes/'.$theme.'/images/header-logo.';
$customLogoBase = api_get_path(SYS_PUBLIC_PATH).'css/themes/'.$theme.'/images/header-logo-custom.';
$site_name = api_get_setting('siteName');
$siteName = api_get_setting('siteName');
$attributes = array(
'title' => $site_name,
'title' => $siteName,
'class' => 'img-responsive',
'id' => 'header-logo'
);
$testServer = api_get_setting('server_type');
if ($testServer == 'test' && is_file($logoBase . 'svg')) {
$logo = $logoBase . 'svg';
$attributes['width'] = '245';
$attributes['height'] = '68';
$image_url = api_get_path(WEB_CSS_PATH).'themes/'.$theme.'/images/header-logo.svg';
$imageUrl = api_get_path(WEB_CSS_PATH).'themes/'.$theme.'/images/header-logo.svg';
} else {
$logo = $logoBase . 'png';
$image_url = api_get_path(WEB_CSS_PATH).'themes/'.$theme.'/images/header-logo.png';
$customLogo = $customLogoBase . 'png';
$imageUrl = api_get_path(WEB_CSS_PATH).'themes/'.$theme.'/images/header-logo.png';
$customImageUrl = api_get_path(WEB_CSS_PATH).'themes/'.$theme.'/images/header-logo-custom.png';
}
if (file_exists($logo)) {
$site_name = api_get_setting('Institution').' - '.$site_name;
if (file_exists($customLogo)) {
$siteName = api_get_setting('Institution').' - '.$siteName;
$customLogo = Display::img(
$customImageUrl,
$siteName,
$attributes
);
$html .= Display::url($customLogo, api_get_path(WEB_PATH).'index.php');
} elseif (file_exists($logo)) {
$siteName = api_get_setting('Institution').' - '.$siteName;
$logo = Display::img(
$image_url,
$site_name,
$imageUrl,
$siteName,
$attributes
);
$html .= Display::url($logo, api_get_path(WEB_PATH).'index.php');
} else {
$html .= '<a href="'.api_get_path(WEB_PATH).'index.php" target="_top">'.$site_name.'</a>';
$html .= '<a href="'.api_get_path(WEB_PATH).'index.php" target="_top">'.$siteName.'</a>';
$iurl = api_get_setting('InstitutionUrl');
$iname = api_get_setting('Institution');

Loading…
Cancel
Save