mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-21 08:12:26 +02:00
Merge remote-tracking branch 'origin/support/3.0' into develop
# Conflicts: # application/twigextension.class.inc.php # datamodels/2.x/authent-cas/composer.json # datamodels/2.x/authent-cas/composer.lock # datamodels/2.x/authent-cas/main.php # datamodels/2.x/authent-cas/vendor/apereo/phpcas/composer.json # datamodels/2.x/authent-cas/vendor/composer/ClassLoader.php # datamodels/2.x/authent-cas/vendor/composer/autoload_classmap.php # datamodels/2.x/authent-cas/vendor/composer/autoload_psr4.php # datamodels/2.x/authent-cas/vendor/composer/autoload_real.php # datamodels/2.x/authent-cas/vendor/composer/autoload_static.php # datamodels/2.x/authent-cas/vendor/composer/installed.json # datamodels/2.x/itop-portal-base/portal/src/Twig/AppExtension.php # lib/apereo/phpcas/source/CAS.php # lib/apereo/phpcas/source/CAS/Client.php # lib/apereo/phpcas/source/CAS/Languages/Galego.php # lib/apereo/phpcas/source/CAS/Languages/Portuguese.php # lib/symfony/cache-contracts/InstalledVersions.php # lib/symfony/cache-contracts/installed.php # lib/symfony/cache-contracts/platform_check.php # sources/Application/UI/Base/Layout/NavigationMenu/NavigationMenu.php # sources/application/TwigBase/Twig/Extension.php
This commit is contained in:
@@ -139,6 +139,7 @@ if (!defined('PORTAL_ID'))
|
||||
// Env. vars to be used in templates and others
|
||||
$_ENV['COMBODO_CURRENT_ENVIRONMENT'] = utils::GetCurrentEnvironment();
|
||||
$_ENV['COMBODO_ABSOLUTE_URL'] = utils::GetAbsoluteUrlAppRoot();
|
||||
$_ENV['COMBODO_CONF_APP_ICON_URL'] = MetaModel::GetConfig()->Get('app_icon_url');
|
||||
$_ENV['COMBODO_MODULES_ABSOLUTE_URL'] = utils::GetAbsoluteUrlModulesRoot();
|
||||
$_ENV['COMBODO_PORTAL_BASE_ABSOLUTE_URL'] = utils::GetAbsoluteUrlModulesRoot().'itop-portal-base/portal/public/';
|
||||
$_ENV['COMBODO_PORTAL_BASE_ABSOLUTE_PATH'] = MODULESROOT.'/itop-portal-base/portal/public/';
|
||||
|
||||
@@ -28,6 +28,7 @@ parameters:
|
||||
# Used in templates
|
||||
combodo.current_environment: '%env(string:COMBODO_CURRENT_ENVIRONMENT)%'
|
||||
combodo.absolute_url: '%env(string:COMBODO_ABSOLUTE_URL)%'
|
||||
combodo.conf.app_icon_url: '%env(string:COMBODO_CONF_APP_ICON_URL)%'
|
||||
combodo.modules.absolute_url: '%env(string:COMBODO_MODULES_ABSOLUTE_URL)%'
|
||||
combodo.modules.absolute_path: !php/const MODULESROOT
|
||||
combodo.portal.base.absolute_url: '%env(string:COMBODO_PORTAL_BASE_ABSOLUTE_URL)%'
|
||||
|
||||
@@ -19,35 +19,192 @@
|
||||
|
||||
namespace Combodo\iTop\Portal\Twig;
|
||||
|
||||
use Combodo\iTop\Application\TwigBase\Twig\Extension;
|
||||
use AttributeDate;
|
||||
use AttributeDateTime;
|
||||
use AttributeText;
|
||||
use Dict;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig_SimpleFilter;
|
||||
use Twig_SimpleFunction;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* Class AppExtension
|
||||
*
|
||||
* Automatically loaded by portal's Symfony configuration to register TWIG extensions.
|
||||
* The class must be kept by it is using the factorized filters/functions of the iTop core.
|
||||
*
|
||||
* @package Combodo\iTop\Portal\Twig
|
||||
* @since 2.7.0
|
||||
* @author Bruno Da Silva <bruno.dasilva@combodo.com>
|
||||
* @deprected 3.1.0 N°4287
|
||||
*/
|
||||
class AppExtension extends AbstractExtension
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @return array|\Twig\TwigFilter[]|\Twig_SimpleFilter[]
|
||||
*/
|
||||
public function getFilters()
|
||||
{
|
||||
return Extension::GetFilters();
|
||||
$filters = array();
|
||||
// Filter to translate a string via the Dict::S function
|
||||
// Usage in twig: {{ 'String:ToTranslate'|dict_s }}
|
||||
$filters[] = new Twig_SimpleFilter('dict_s',
|
||||
function ($sStringCode, $sDefault = null, $bUserLanguageOnly = false) {
|
||||
return Dict::S($sStringCode, $sDefault, $bUserLanguageOnly);
|
||||
}
|
||||
);
|
||||
|
||||
// Filter to format a string via the Dict::Format function
|
||||
// Usage in twig: {{ 'String:ToTranslate'|dict_format() }}
|
||||
$filters[] = new Twig_SimpleFilter('dict_format',
|
||||
function ($sStringCode, $sParam01 = null, $sParam02 = null, $sParam03 = null, $sParam04 = null) {
|
||||
return Dict::Format($sStringCode, $sParam01, $sParam02, $sParam03, $sParam04);
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* Filter to format output
|
||||
* example a DateTime is converted to user format
|
||||
* Usage in twig: {{ 'String:ToFormat'|output_format }}
|
||||
*
|
||||
* @since 3.0.0
|
||||
*/
|
||||
$filters[] = new Twig_SimpleFilter('date_format',
|
||||
function ($sDate) {
|
||||
try
|
||||
{
|
||||
if (preg_match('@^\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d$@', trim($sDate)))
|
||||
{
|
||||
return AttributeDateTime::GetFormat()->Format($sDate);
|
||||
}
|
||||
if (preg_match('@^\d\d\d\d-\d\d-\d\d$@', trim($sDate)))
|
||||
{
|
||||
return AttributeDate::GetFormat()->Format($sDate);
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
}
|
||||
|
||||
return $sDate;
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* Filter to format output
|
||||
* example a DateTime is converted to user format
|
||||
* Usage in twig: {{ 'String:ToFormat'|output_format }}
|
||||
*
|
||||
* @since 3.0.0
|
||||
*/
|
||||
$filters[] = new Twig_SimpleFilter('size_format',
|
||||
function ($sSize) {
|
||||
return utils::BytesToFriendlyFormat($sSize);
|
||||
}
|
||||
);
|
||||
|
||||
// Filter to enable base64 encode/decode
|
||||
// Usage in twig: {{ 'String to encode'|base64_encode }}
|
||||
$filters[] = new Twig_SimpleFilter('base64_encode', 'base64_encode');
|
||||
$filters[] = new Twig_SimpleFilter('base64_decode', 'base64_decode');
|
||||
|
||||
// Filter to enable json decode (encode already exists)
|
||||
// Usage in twig: {{ aSomeArray|json_decode }}
|
||||
$filters[] = new Twig_SimpleFilter('json_decode', function ($sJsonString, $bAssoc = false) {
|
||||
return json_decode($sJsonString, $bAssoc);
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* Filter to sanitize a text
|
||||
* Usage in twig: {{ 'variable_name:to-sanitize'|sanitize(constant('utils::ENUM_SANITIZATION_FILTER_VARIABLE_NAME')) }}
|
||||
*
|
||||
* @uses \utils::Sanitize()
|
||||
* @since 3.0.0
|
||||
*/
|
||||
$filters[] = new Twig_SimpleFilter('sanitize', function (string $sString, string $sFilter) {
|
||||
return utils::Sanitize($sString, '', $sFilter);
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* Filter to transform the wiki syntax ONLY into HTML.
|
||||
*
|
||||
* @uses \AttributeText::RenderWikiHtml()
|
||||
* @since 3.0.0
|
||||
*/
|
||||
$filters[] = new Twig_SimpleFilter('render_wiki_to_html', function ($sString) {
|
||||
return AttributeText::RenderWikiHtml($sString, true /* Important, otherwise hyperlinks will be tranformed as well */);
|
||||
}
|
||||
);
|
||||
|
||||
// Filter to add itopversion to an url
|
||||
$filters[] = new Twig_SimpleFilter('add_itop_version', function ($sUrl) {
|
||||
$sUrl = utils::AddParameterToUrl($sUrl, 'itopversion', ITOP_VERSION);
|
||||
|
||||
return $sUrl;
|
||||
});
|
||||
|
||||
// Filter to add a module's version to an url
|
||||
$filters[] = new Twig_SimpleFilter('add_module_version', function ($sUrl, $sModuleName) {
|
||||
$sModuleVersion = utils::GetCompiledModuleVersion($sModuleName);
|
||||
$sUrl = utils::AddParameterToUrl($sUrl, 'moduleversion', $sModuleVersion);
|
||||
|
||||
return $sUrl;
|
||||
});
|
||||
|
||||
/**
|
||||
* var_export can be used for example to transform a PHP boolean to 'true' or 'false' strings
|
||||
* @see https://www.php.net/manual/fr/function.var-export.php
|
||||
*
|
||||
* @since 3.0.0
|
||||
*/
|
||||
$filters[] = new Twig_SimpleFilter('var_export', 'var_export');
|
||||
|
||||
//since 2.7.7 3.0.2 3.1.0 N°4867 "Twig content not allowed" error when use the extkey widget search icon in the user portal
|
||||
//overwrite native twig filter : disable use of 'system' filter
|
||||
$filters[] = new Twig_SimpleFilter('filter', function ($array, $arrow) {
|
||||
if ($arrow == 'system'){
|
||||
return json_encode($array);
|
||||
}
|
||||
return twig_array_filter($array, $arrow);
|
||||
});
|
||||
|
||||
return $filters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @return array|\Twig\TwigFunction[]|\Twig_SimpleFunction[]
|
||||
*/
|
||||
public function getFunctions()
|
||||
{
|
||||
return Extension::GetFunctions();
|
||||
$functions = array();
|
||||
|
||||
// Function to check our current environment
|
||||
// Usage in twig: {% if is_development_environment() %}
|
||||
$functions[] = new Twig_SimpleFunction('is_development_environment', function () {
|
||||
return utils::IsDevelopmentEnvironment();
|
||||
});
|
||||
|
||||
/**
|
||||
* Function to get iTop's app root absolute URL (eg. https://aaa.bbb.ccc/xxx/yyy/)
|
||||
* Usage in twig: {{ get_absolute_url_app_root() }}
|
||||
*
|
||||
* @since 3.0.0
|
||||
*/
|
||||
$functions[] = new Twig_SimpleFunction('get_absolute_url_app_root', function () {
|
||||
return utils::GetAbsoluteUrlAppRoot();
|
||||
});
|
||||
|
||||
/**
|
||||
* Function to get iTop's modules root absolute URL (eg. https://aaa.bbb.ccc/xxx/yyy/env-zzz/)
|
||||
* Usage in twig: {{ get_absolute_url_modules_root() }}
|
||||
*
|
||||
* @since 3.0.0
|
||||
*/
|
||||
$functions[] = new Twig_SimpleFunction('get_absolute_url_modules_root', function () {
|
||||
return utils::GetAbsoluteUrlModulesRoot();
|
||||
});
|
||||
|
||||
return $functions;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -188,7 +188,7 @@
|
||||
<span class="icon-bar"></span>
|
||||
</button>
|
||||
{% block pNavigationTopMenuLogo %}
|
||||
<a class="navbar-brand pull-right" href="{{ get_config_parameter('app_icon_url') }}">
|
||||
<a class="navbar-brand pull-right" href="{{ app['combodo.conf.app_icon_url'] }}">
|
||||
{% if app['combodo.portal.instance.conf'].properties.logo is not null %}
|
||||
<img src="{{ app['combodo.portal.instance.conf'].properties.logo }}" alt="{{ app['combodo.portal.instance.conf'].properties.name|dict_s }}" />
|
||||
{% else %}
|
||||
@@ -316,7 +316,7 @@
|
||||
{% if app['kernel'].debug == true %}
|
||||
<div style="position: fixed; bottom: 0px; left: 0px; z-index: 9999;">Debug: Screen size <span class="hidden-sm hidden-md hidden-lg">XS</span><span class="hidden-xs hidden-md hidden-lg">SM</span><span class="hidden-xs hidden-sm hidden-lg">MD</span><span class="hidden-xs hidden-sm hidden-md">LG</span></div>
|
||||
{% endif %}
|
||||
<a href="{{ get_config_parameter('app_icon_url') }}" title="{{ app['combodo.portal.instance.conf'].properties.name|dict_s }}">
|
||||
<a href="{{ app['combodo.conf.app_icon_url'] }}" title="{{ app['combodo.portal.instance.conf'].properties.name|dict_s }}">
|
||||
<img src="{{ app['combodo.portal.instance.conf'].properties.logo }}" alt="{{ app['combodo.portal.instance.conf'].properties.name|dict_s }}" />
|
||||
</a>
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user