Implement optional use of SVG icons. Only enabled in test-server mode for now - refs #7359

1.10.x
Yannick Warnier 10 years ago
parent 747141bfac
commit d8b40b475d
  1. 36
      main/inc/lib/display.lib.php
  2. 2
      main/inc/lib/security.lib.php

@ -745,19 +745,20 @@ class Display
$size = ICON_SIZE_SMALL,
$show_text = true,
$return_only_path = false
) {
)
{
$code_path = api_get_path(SYS_CODE_PATH);
$code_path = api_get_path(SYS_CODE_PATH);
$w_code_path = api_get_path(WEB_CODE_PATH);
$image = trim($image);
$theme = 'css/'.api_get_visual_theme().'/icons/';
$theme = 'css/' . api_get_visual_theme() . '/icons/';
$icon = '';
$size_extra = '';
if (isset($size)) {
$size = intval($size);
$size_extra = $size.'/';
$size_extra = $size . '/';
} else {
$size = ICON_SIZE_SMALL;
}
@ -770,12 +771,37 @@ class Display
$icon = $w_code_path.'img/icons/'.$size_extra.$image;
} else {
//Checking the img/ folder
$icon = $w_code_path.'img/'.$image;
$icon = $w_code_path . 'img/' . $image;
}
// Special code to enable SVG - refs #7359 - Needs more work
// The code below does something else to "test out" SVG: for each icon,
// it checks if there is an SVG version. If so, it uses it.
// When moving this to production, the return_icon() calls should
// ask for the SVG version directly
if (Chamilo::is_test_server()) {
$svgImage = substr($image, 0, -3) . 'svg';
if (is_file($code_path . $theme . 'svg/' . $svgImage)) {
error_log(__LINE__);
$icon = $w_code_path . $theme . 'svg/' . $svgImage;
} elseif (is_file($code_path . 'img/icons/svg/' . $svgImage)) {
error_log(__LINE__);
$icon = $w_code_path . 'img/icons/svg/' . $svgImage;
}
if (empty($additional_attributes['height'])) {
$additional_attributes['height'] = $size;
}
if (empty($additional_attributes['width'])) {
$additional_attributes['width'] = $size;
}
}
$icon = api_get_cdn_path($icon);
if ($return_only_path) {
return $icon;
}
error_log($icon);
$img = self::img($icon, $alt_text, $additional_attributes);
if (SHOW_TEXT_NEAR_ICONS == true and !empty($alt_text)) {

@ -446,7 +446,7 @@ class Security
*/
public static function filter_img_path($image_path)
{
static $allowed_extensions = array('png', 'gif', 'jpg', 'jpeg');
static $allowed_extensions = array('png', 'gif', 'jpg', 'jpeg', 'svg', 'webp');
$image_path = htmlspecialchars(trim($image_path)); // No html code is allowed.
// We allow static images only, query strings are forbidden.
if (strpos($image_path, '?') !== false) {

Loading…
Cancel
Save