Show custom logo on PDF export and emails - refs BT#11424

remotes/angel/1.11.x
Angel Fernando Quiroz Campos 8 years ago
parent 1b557c4316
commit 3fa47967b8
  1. 21
      main/admin/settings.lib.php
  2. 64
      main/inc/lib/banner.lib.php
  3. 21
      main/inc/lib/pdf.lib.php
  4. 66
      src/Chamilo/CoreBundle/Component/Utils/ChamiloApi.php

@ -2,6 +2,7 @@
/* For licensing terms, see /license.txt */
use Symfony\Component\Filesystem\Filesystem;
use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
/**
* Library of the settings.php file
@ -380,11 +381,13 @@ function handleStylesheets()
$url = api_get_path(WEB_CSS_PATH).'themes/' . $selected . '/images/';
$logoFileName = 'header-logo.png';
$newLogoFileName = 'header-logo-custom' . api_get_current_access_url_id() . '.png';
$webPlatformLogoPath = ChamiloApi::getWebPlatformLogoPath();
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() . '">');
if ($webPlatformLogoPath !== null) {
$logoForm->addLabel(
get_lang('CurrentLogo'),
'<img id="header-logo-custom" src="' . $webPlatformLogoPath . '?' . time() . '">'
);
}
$logoForm->addFile('new_logo', get_lang('UpdateLogo'));
@ -393,7 +396,7 @@ function handleStylesheets()
if (isset($_POST['logo_reset'])) {
if (is_file($dir.$newLogoFileName)) {
unlink($dir.$newLogoFileName);
Display::display_normal_message(get_lang('ResetToTheOriginalLogo'));
echo Display::return_message(get_lang('ResetToTheOriginalLogo'));
echo '<script>'
. '$("#header-logo").attr("src","'.$url.$logoFileName.'");'
. '</script>';
@ -416,15 +419,15 @@ function handleStylesheets()
$status = move_uploaded_file($_FILES['new_logo']['tmp_name'], $dir.$newLogoFileName);
if ($status) {
Display::display_normal_message(get_lang('NewLogoUpdated'));
echo Display::return_message(get_lang('NewLogoUpdated'));
echo '<script>'
. '$("#header-logo").attr("src","'.$url.$newLogoFileName.'");'
. '</script>';
} else {
Display::display_error_message('Error - '.get_lang('UplNoFileUploaded'));
echo Display::return_message('Error - '.get_lang('UplNoFileUploaded'), 'error');
}
} else {
Display::display_error_message('Error - '.get_lang('InvalidImageDimensions'));
Display::return_message('Error - '.get_lang('InvalidImageDimensions'), 'error');
}
}
}
@ -453,7 +456,7 @@ function handleStylesheets()
</script>';
echo Display::tabs(
array(get_lang('Update'),get_lang('UpdateLogo'), get_lang('UploadNewStylesheet')),
array($form_change->return_form(), $logoForm->return_form(), $form->return_form())
array($form_change->return_form(), $logoForm->returnForm(), $form->returnForm())
);
} else {
$form_change->display();

@ -6,6 +6,8 @@
* @package chamilo.include
*/
use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
/**
* Determines the possible tabs (=sections) that are available.
* This function is used when creating the tabs in the third header line and
@ -173,69 +175,13 @@ function getCustomTabs()
*/
function return_logo($theme)
{
$_course = api_get_course_info();
$accessUrlId = api_get_current_access_url_id();
$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$accessUrlId.";
$customLogo = '';
$siteName = api_get_setting('siteName');
$attributes = array(
return ChamiloApi::getPlatformLogo([
'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';
$imageUrl = api_get_path(WEB_CSS_PATH).'themes/'.$theme.'/images/header-logo.svg';
} else {
$logo = $logoBase . '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$accessUrlId.png";
}
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(
$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">'.$siteName.'</a>';
$iurl = api_get_setting('InstitutionUrl');
$iname = api_get_setting('Institution');
if (!empty($iname)) {
$html .= '-&nbsp;<a href="'.$iurl.'" target="_top">'.$iname.'</a>';
}
// External link section a.k.a Department - Department URL
if (isset($_course['extLink']) && $_course['extLink']['name'] != '') {
$html .= '<span class="extLinkSeparator"> - </span>';
if ($_course['extLink']['url'] != '') {
$html .= '<a class="extLink" href="'.$_course['extLink']['url'].'" target="_top">';
$html .= $_course['extLink']['name'];
$html .= '</a>';
} else {
$html .= $_course['extLink']['name'];
}
}
}
return $html;
]);
}
/**

@ -1,6 +1,8 @@
<?php
/* See license terms in /license.txt */
use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
/**
* Class PDF
* @package chamilo.library
@ -93,24 +95,7 @@ class PDF
// Assignments
$tpl->assign('pdf_content', $content);
$organization = api_get_setting('Institution');
$img = api_get_path(SYS_CSS_PATH).'themes/' . $theme . '/images/header-logo.png';
$customImg = api_get_path(SYS_PUBLIC_PATH).'css/themes/' . $theme . '/images/header-logo-custom.png';
// Search for classic logo
if (file_exists($customImg)) {
$img = api_get_path(WEB_CSS_PATH).'themes/' . $theme . '/images/header-logo-custom.png';
$organization = "<img src='$img'>";
} else if (file_exists($img)) {
$img = api_get_path(WEB_CSS_PATH).'themes/' . $theme . '/images/header-logo.png';
$organization = "<img src='$img'>";
} else {
// Just use the platform title.
if (!empty($organization)) {
$organization = '<h2 align="left">'.$organization.'</h2>';
}
}
$organization = ChamiloApi::getPlatformLogo();
// Use custom logo image.
$pdfLogo = api_get_setting('pdf_logo_header');
if ($pdfLogo === 'true') {

@ -63,4 +63,70 @@ class ChamiloApi
);
}
/**
* Get the platform logo path
* @return null|string
*/
public static function getWebPlatformLogoPath()
{
$theme = api_get_visual_theme();
$accessUrlId = api_get_current_access_url_id();
$customLogoPath = "themes/$theme/images/header-logo-custom$accessUrlId.png";
if (file_exists(api_get_path(SYS_PUBLIC_PATH) . "css/$customLogoPath")) {
return api_get_path(WEB_CSS_PATH) . $customLogoPath;
}
$originalLogoPath = "themes/$theme/images/header-logo.png";
if (file_exists(api_get_path(SYS_CSS_PATH) . $originalLogoPath)) {
return api_get_path(WEB_CSS_PATH) . $originalLogoPath;
}
return null;
}
/**
* Get the platform logo.
* Return a <img> if the logo image exists. Otherwise return a <h2> with the institution name.
* @param array $imageAttributes Optional.
* @return string
*/
public static function getPlatformLogo($imageAttributes = [])
{
$logoPath = self::getWebPlatformLogoPath();
$insitution = api_get_setting('Institution');
$insitutionUrl = api_get_setting('InstitutionUrl');
$siteName = api_get_setting('siteName');
if ($logoPath === null) {
$headerLogo = \Display::url($siteName, api_get_path(WEB_PATH) . 'index.php');
if (!empty($insitutionUrl) && !empty($insitution)) {
$headerLogo .= ' - ' . \Display::url($insitution, $insitutionUrl);
}
$courseInfo = api_get_course_info();
if (isset($courseInfo['extLink']) && !empty($courseInfo['extLink']['name'])) {
$headerLogo .= '<span class="extLinkSeparator"> - </span>';
if (!empty($courseInfo['extLink']['url'])) {
$headerLogo .= \Display::url(
$courseInfo['extLink']['name'],
$courseInfo['extLink']['url'],
['class' => 'extLink']
);
} else if (!empty($courseInfo['extLink']['url'])) {
$headerLogo .= $courseInfo['extLink']['url'];
}
}
return \Display::tag('h2', $headerLogo, ['class' => 'text-left']);
}
$image = \Display::img($logoPath, $insitution, $imageAttributes);
return \Display::url($image, api_get_path(WEB_PATH) . 'index.php');
}
}

Loading…
Cancel
Save