Skip to content
Snippets Groups Projects
Commit 89e11724 authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms Committed by David Siegfried
Browse files

remove less compilation for plugins, fixes #2720

Closes #2720

Merge request studip/studip!1838
parent c9244d1a
No related branches found
No related tags found
No related merge requests found
......@@ -13,7 +13,8 @@
- Die Funktion `smile()` wurde entfernt. Sie kann ersatzlos entfernt werden. ([Issue #3158](https://gitlab.studip.de/studip/studip/-/issues/3158))
- Die Funktion `transformBeforeSave()` wurde entfernt. Sie kann ersatzlos entfernt werden. ([Issue #3159](https://gitlab.studip.de/studip/studip/-/issues/3159))
- Die schon lange nicht mehr genutzten Methoden zum Setzen, Auslesen und Enfernen von Schmuckgrafiken von Bildern für die Sidebar wurde entfernt. Die Methoden `Sidebar::setImage()`, `Sidebar::getImage()` sowie `Sidebar::removeImage()` müssen ersatzlos entfernt werden. ([Issue #3157](https://gitlab.studip.de/studip/studip/-/issues/3157))
- Der zweite Parameter für die Methode `Navigation::setImage()` wurde entfernt. Der Parameter schien sich auf das Bild zu beziehen, hat aber Attribute an dem Link gesetzt. Stattdessen muss die Methode `Navigation::setLinkAttributes()` verwendet werden. ([Issue #3578](https://gitlab.studip.de/studip/studip/-/issues/3578))
- Der zweite Parameter für die Methode `Navigation::setImage()` wurde entfernt. Der Parameter schien sich auf das Bild zu beziehen, hat aber Attribute an dem Link gesetzt. Stattdessen muss die Methode `Navigation::setLinkAttributes()` verwendet werden. ([Issue #3578](https://gitlab.studip.de/studip/studip/-/issues/3578))
- Die Unterstützung für LESS-Stylsheets in Plugins wurde entfernt. Als Alternative wird SCSS unterstützt. ([Issue #2720](https://gitlab.studip.de/studip/studip/-/issues/2720))
## Security related issues
......
......@@ -25,7 +25,6 @@
"tecnickcom/tcpdf": "^6.3",
"scssphp/scssphp": "^1.4",
"symfony/yaml": "^5.0",
"mishal/iless": "^2.2",
"ezyang/htmlpurifier": "^4.13",
"davefx/phplot": "^6.2",
"jasig/phpcas": "1.5",
......
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "0cd6741cbad14a70b1d619d5c98f7378",
"content-hash": "76e4dce9372399bca6af1762cd407649",
"packages": [
{
"name": "algo26-matthias/idna-convert",
......@@ -1356,63 +1356,6 @@
},
"time": "2022-12-02T22:17:43+00:00"
},
{
"name": "mishal/iless",
"version": "2.2.0",
"source": {
"type": "git",
"url": "https://github.com/mishal/iless.git",
"reference": "d75af501ab0ca411efd041faa53e6652f1602553"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/mishal/iless/zipball/d75af501ab0ca411efd041faa53e6652f1602553",
"reference": "d75af501ab0ca411efd041faa53e6652f1602553",
"shasum": ""
},
"require": {
"php": ">=5.4.0"
},
"bin": [
"bin/iless"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.1-dev"
}
},
"autoload": {
"psr-4": {
"ILess\\": "lib/ILess"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "ILess contributors",
"homepage": "https://github.com/mishal/iless/wiki/Contributors"
}
],
"description": "Less.js port to PHP",
"homepage": "http://github.com/mishal/iless",
"keywords": [
"compiler",
"css",
"less",
"less.js",
"lesscss",
"parser"
],
"support": {
"issues": "https://github.com/mishal/iless/issues",
"source": "https://github.com/mishal/iless/tree/master"
},
"time": "2016-04-25T07:03:37+00:00"
},
{
"name": "monolog/monolog",
"version": "2.9.1",
......
<?php
namespace Assets;
use Assets;
use StudipCacheFactory;
use ILess\Autoloader;
use ILess\Importer\FileSystemImporter;
use ILess\Parser;
/**
* LESS Compiler for assets.
*
* Uses ILess by mishal <https://github.com/mishal/iless>.
*
* @author Jan-Hendrik Willms <tleilax+studip@gmail.com>
* @license GPL2 or any later version
* @since Stud.IP 4.4
* @deprecated since Stud.IP 5.4 and will be removed in Stud.IP 6.0
*/
class LESSCompiler implements Compiler
{
const CACHE_KEY = '/assets/less-prefix';
private static $instance = null;
/**
* Returns an instance of the compiler
* @return Assets\LESSCompiler instance
*/
public static function getInstance()
{
if (self::$instance === null) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Private constructor to enforce singleton.
*/
private function __construct()
{
Autoloader::register();
}
/**
* Compiles a less string. This method will add all neccessary imports
* and variables for Stud.IP so almost all mixins and variables of the
* core system can be used. This includes colors and icons.
*
* @param string $input LESS content to compile
* @param array $variables Additional variables for the LESS compilation
* @return string containing the generated CSS
*/
public function compile($input, array $variables = []): string
{
// Show deprecation notice
if (\Studip\ENV === 'development') {
\PageLayout::postMessage(
\MessageBox::info(
_('Das Verwenden von LESS-Stylesheets in Plugins ist deprecated und wird zu Stud.IP 6.0 entfernt.'),
[
_('Als Alternative steht die Verwendung von SCSS bereit.'),
_('Bitte stellen Sie Ihre Plugins entsprechend um bzw. geben den Plugin-AutorInnen Bescheid.'),
]
),
'less-deprecation-notice'
);
}
$less = $this->getPrefix() . $input;
$variables['image-path'] = '"' . Assets::url('images') . '"';
// Disable warnings since we currently have no other means to get rid
// of them
// TODO: Look again into this (2022-06-23)
$error_reporting = error_reporting();
error_reporting($error_reporting & ~E_WARNING);
$parser = new Parser(['strictMath' => true], null, [
new FileSystemImporter(["{$GLOBALS['STUDIP_BASE_PATH']}/resources/"])
]);
$parser->setVariables($variables);
$parser->parseString($less);
$css = $parser->getCSS();
// Restore error reporting
error_reporting($error_reporting);
return $css;
}
/**
* Generates the less prefix containing the variables and mixins of the
* Stud.IP core system.
* This prefix will be cached in Stud.IP's cache in order to minimize
* disk accesses.
*
* @return String containing the neccessary prefix
*/
private function getPrefix()
{
$cache = StudipCacheFactory::getCache();
$prefix = $cache->read(self::CACHE_KEY);
if ($prefix === false) {
$prefix = '';
// Load mixins and change relative to absolute filenames
$mixin_file = $GLOBALS['STUDIP_BASE_PATH'] . '/resources/assets/stylesheets/mixins.less';
foreach (file($mixin_file) as $mixin) {
if (!preg_match('/@import(.*?) "(.*)";/', $mixin, $match)) {
continue;
}
$core_file = "{$GLOBALS['STUDIP_BASE_PATH']}/resources/assets/stylesheets/{$match[2]}";
$prefix .= sprintf('@import%s "%s";' . "\n", $match[1], $core_file);
}
// Add adjusted image paths
$prefix .= sprintf('@image-path: "%s";', Assets::url('images')) . "\n";
$prefix .= '@icon-path: "@{image-path}/icons/16";' . "\n";
$cache->write(self::CACHE_KEY, $prefix);
}
return $prefix;
}
}
......@@ -14,8 +14,8 @@ class PluginAssetFactory implements AssetFactory
* Restores or create a css file based on the given information.
*
* @param String $filename Filename of the original file
* @param Array $metadata Potential metadata
* @return Assets\PluginAsset
* @param array $metadata Potential metadata
* @return PluginAsset
*/
public function createCSSFile($filename, array $metadata = [])
{
......@@ -44,9 +44,9 @@ class PluginAssetFactory implements AssetFactory
/**
* Restores or create a js file based on the given information.
*
* @param String $filename Filename of the original file
* @param Array $metadata Potential metadata
* @return Assets\PluginAsset
* @param string $filename Filename of the original file
* @param array $metadata Potential metadata
* @return PluginAsset
*/
public function createJSFile($filename, array $metadata = [])
{
......
......@@ -48,7 +48,7 @@ class SASSCompiler implements Compiler
* core system can be used. This includes colors and icons.
*
* @param String $input Scss content to compile
* @param array $variables Additional variables for the LESS compilation
* @param array $variables Additional variables for the SCSS compilation
* @return String containing the generated CSS
*/
public function compile($input, array $variables = [])
......@@ -73,7 +73,7 @@ class SASSCompiler implements Compiler
}
/**
* Generates the less prefix containing the variables and mixins of the
* Generates the scss prefix containing the variables and mixins of the
* Stud.IP core system.
* This prefix will be cached in Stud.IP's cache in order to minimize
* disk accesses.
......
......@@ -12,7 +12,7 @@ trait PluginAssetsTrait
* Adds an asset while detecting the type automatically.
*
* @param string $asset Asset to add
* @param array $variables Variables for the LESS/SCSS compiler, unused for JS
* @param array $variables Variables for the SCSS compiler, unused for JS
* @since Stud.IP 5.4
*/
public function addAsset(string $asset, array $variables = []): void
......@@ -29,7 +29,7 @@ trait PluginAssetsTrait
* Adds many assets while detecting the type automatically.
*
* @param string[] $assets Assets to add
* @param array $variables Variables for the LESS/SCSS compiler, unused
* @param array $variables Variables for the SCSS compiler, unused
* for JS
* @param bool $combine If true, the assets will be combined into one
* single file for each type
......@@ -61,7 +61,7 @@ trait PluginAssetsTrait
* Adds many stylesheeets at once.
* @param array $filenames List of relative filenames
* @param array $variables Optional array of variables to pass to the
* LESS compiler
* SCSS compiler
* @param array $link_attr Attributes to pass to the link elements
* @param string $path Common path prefix for all filenames
*/
......@@ -96,18 +96,18 @@ trait PluginAssetsTrait
}
/**
* Includes given stylesheet in page, compiles less if neccessary
* Includes given stylesheet in page, compiles scss if neccessary
*
* @param string $filename Name of the stylesheet (css or less) to include
* @param string $filename Name of the stylesheet (css or scss) to include
* (relative to plugin directory)
* @param array $variables Optional array of variables to pass to the
* LESS compiler
* SCSS compiler
* @param array $link_attr Attributes to pass to the link element
*/
protected function addStylesheet($filename, array $variables = [], array $link_attr = [])
{
$extension = pathinfo($filename, PATHINFO_EXTENSION);
if (!in_array($extension, ['less', 'scss'])) {
if ($extension != 'scss') {
PageLayout::addStylesheet(
"{$this->getPluginURL()}/{$filename}?v={$this->getPluginVersion()}",
$link_attr
......@@ -250,11 +250,7 @@ trait PluginAssetsTrait
$contents = file_get_contents($filename);
$extension = pathinfo($filename, PATHINFO_EXTENSION);
if ($extension === 'less') {
$contents = Assets\LESSCompiler::getInstance()->compile($contents, $variables + [
'plugin-path' => $this->getPluginURL(),
]);
} elseif ($extension === 'scss') {
if ($extension === 'scss') {
$contents = Assets\SASSCompiler::getInstance()->compile($contents, $variables + [
'plugin-path' => '"' . $this->getPluginURL() . '"',
]);
......@@ -277,7 +273,7 @@ trait PluginAssetsTrait
return 'js';
}
if (in_array($extension, ['css', 'less', 'scss'])) {
if (in_array($extension, ['css', 'scss'])) {
return 'css';
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment