aboutsummaryrefslogtreecommitdiff
path: root/lib/classes
diff options
context:
space:
mode:
authorJan-Hendrik Willms <tleilax+studip@gmail.com>2024-03-15 15:43:42 +0000
committerDavid Siegfried <david.siegfried@uni-vechta.de>2024-03-15 15:43:42 +0000
commit89e1172483af3381dfc782690024452104f5c0c0 (patch)
treeb564cf190d30807ba831c6a8e19455ad7bb06713 /lib/classes
parentc9244d1a2f101939e309e4b563bb3bf7bbb8bae5 (diff)
remove less compilation for plugins, fixes #2720
Closes #2720 Merge request studip/studip!1838
Diffstat (limited to 'lib/classes')
-rw-r--r--lib/classes/assets/LESSCompiler.php131
-rw-r--r--lib/classes/assets/PluginAssetFactory.php10
-rw-r--r--lib/classes/assets/SASSCompiler.php4
3 files changed, 7 insertions, 138 deletions
diff --git a/lib/classes/assets/LESSCompiler.php b/lib/classes/assets/LESSCompiler.php
deleted file mode 100644
index ccb8371..0000000
--- a/lib/classes/assets/LESSCompiler.php
+++ /dev/null
@@ -1,131 +0,0 @@
-<?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;
- }
-}
diff --git a/lib/classes/assets/PluginAssetFactory.php b/lib/classes/assets/PluginAssetFactory.php
index c4b394d..82789dd 100644
--- a/lib/classes/assets/PluginAssetFactory.php
+++ b/lib/classes/assets/PluginAssetFactory.php
@@ -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 = [])
{
diff --git a/lib/classes/assets/SASSCompiler.php b/lib/classes/assets/SASSCompiler.php
index bb519d1..2dcda2d 100644
--- a/lib/classes/assets/SASSCompiler.php
+++ b/lib/classes/assets/SASSCompiler.php
@@ -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.