N°7397 - Update welcome popup content for iTop 3.2 (#648)

* N°7397 - Update welcome popup content for iTop 3.2

* N°7397 - Display illustrations as restylable SVG, add extension to twig to support absolute url in source function

* N°7397 - Update 3.2 welcome messages dictionaries, add French translations and set up other languages files

---------

Co-authored-by: Stephen Abello <stephen.abello@combodo.com>
This commit is contained in:
Molkobain
2024-07-15 16:12:12 +02:00
committed by GitHub
parent f0c37bd69e
commit 1d67d50a20
27 changed files with 879 additions and 284 deletions

View File

@@ -16,6 +16,9 @@ use Combodo\iTop\Renderer\BlockRenderer;
use Dict;
use Exception;
use Twig\Environment;
use Twig\Extension\CoreExtension;
use Twig\Loader\FilesystemLoader;
use Twig\Source;
use Twig\TwigFilter;
use Twig\TwigFunction;
use utils;
@@ -202,6 +205,31 @@ class Extension
['is_safe' => ['html']]
);
/** @since 3.2.0 */
$aFunctions[] = new TwigFunction('source_abs', function (Environment $oEnv, $sUrlAbsName) {
// Extract the source path from the absolute url and replace it with approot
$sAppRootAbsName = str_replace(utils::GetAbsoluteUrlAppRoot(), APPROOT, $sUrlAbsName);
$oLoader = $oEnv->getLoader();
// Check if the file is in any of the twig paths
if($oLoader instanceof FilesystemLoader) {
$aPaths = $oLoader->getPaths();
foreach ($aPaths as $sPath) {
$sTwigPathRelativeName = substr($sAppRootAbsName, strlen($sPath) + 1);
// If we find our path in the absolute url and the file actually exist, return it
if (str_contains($sAppRootAbsName, $sPath) && $oLoader->exists($sTwigPathRelativeName)) {
return $oLoader->getSourceContext($sTwigPathRelativeName)->getCode();
}
}
}
// Otherwise return empty content
$oEmptySource = new Source('', $sUrlAbsName, '');
return $oEmptySource->getCode();
},
['needs_environment' => true,
'is_safe' => ['all']]
);
return $aFunctions;
}
}