N°8796 - Add PHP code style validation in iTop and extensions - format whole code base

This commit is contained in:
odain
2025-11-07 15:39:53 +01:00
parent 12f23113f5
commit 890a2568c8
2110 changed files with 53099 additions and 63885 deletions

View File

@@ -37,7 +37,7 @@ class CKEditorHelper
*
* @return array
*/
public static function GetCkeditorConfiguration(bool $bWithMentions, ?string $sInitialValue, array $aOverloadConfiguration = []) : array
public static function GetCkeditorConfiguration(bool $bWithMentions, ?string $sInitialValue, array $aOverloadConfiguration = []): array
{
// Extract language from user preferences
$sLanguageCountry = trim(UserRights::GetUserLanguage());
@@ -45,25 +45,24 @@ class CKEditorHelper
$aSanitizerConfiguration = self::GetDOMSanitizerForCKEditor();
// configuration
$aConfiguration = array(
$aConfiguration = [
'language' => $sLanguage,
'maximize' => [],
'detectChanges' => [
'initialValue' => $sInitialValue
'initialValue' => $sInitialValue,
],
'objectShortcut' => [
'buttonLabel' => Dict::S('UI:ObjectShortcutInsert')
'buttonLabel' => Dict::S('UI:ObjectShortcutInsert'),
],
'htmlSupport' => $aSanitizerConfiguration,
);
];
// Mentions
if($bWithMentions){
try{
if ($bWithMentions) {
try {
$aMentionConfiguration = self::GetMentionConfiguration();
$aConfiguration['mention'] = $aMentionConfiguration;
}
catch(Exception $e){
} catch (Exception $e) {
ExceptionLog::LogException($e);
}
}
@@ -78,7 +77,7 @@ class CKEditorHelper
* @return array|array[]
* @throws \Exception
*/
private static function GetMentionConfiguration() : array
private static function GetMentionConfiguration(): array
{
// initialize feeds
$aMentionConfiguration = ['feeds' => []];
@@ -87,7 +86,7 @@ class CKEditorHelper
$aMentionsAllowedClasses = MetaModel::GetConfig()->Get('mentions.allowed_classes');
// iterate throw classes...
foreach($aMentionsAllowedClasses as $sMentionMarker => $sMentionScope) {
foreach ($aMentionsAllowedClasses as $sMentionMarker => $sMentionScope) {
// Retrieve mention class
// - First test if the conf is a simple data model class
@@ -108,7 +107,7 @@ class CKEditorHelper
'minimumCharacters' => MetaModel::GetConfig()->Get('min_autocomplete_chars'),
'feed_type' => 'ajax',
'feed_ajax_options' => [
'url' => utils::GetAbsoluteUrlAppRoot(). "pages/ajax.render.php?route=object.search_for_mentions&marker=".urlencode($sMentionMarker)."&needle=",
'url' => utils::GetAbsoluteUrlAppRoot()."pages/ajax.render.php?route=object.search_for_mentions&marker=".urlencode($sMentionMarker)."&needle=",
'throttle' => 500,
'marker' => $sMentionMarker,
],
@@ -127,12 +126,12 @@ class CKEditorHelper
*
* @return string|null
*/
public static function PrepareCKEditorValueTextEncodingForTextarea(string $sValue = null) : ?string
public static function PrepareCKEditorValueTextEncodingForTextarea(string $sValue = null): ?string
{
if($sValue === null){
if ($sValue === null) {
return null;
}
return str_replace( '&', '&', $sValue );
return str_replace('&', '&', $sValue);
}
/**
@@ -150,10 +149,9 @@ class CKEditorHelper
{
// link CKEditor JS files
foreach (static::GetJSFilesRelPathsForCKEditor() as $sFile) {
try{
try {
$oPage->LinkScriptFromAppRoot($sFile);
}
catch(Exception $e){
} catch (Exception $e) {
ExceptionLog::LogException($e);
}
}
@@ -166,12 +164,11 @@ class CKEditorHelper
$oPage->add_ready_script("CombodoCKEditorHandler.CreateInstance('#$sInputElementId', $sConfigJS)");
// handle mentions template
if($bWithMentions){
try{
if ($bWithMentions) {
try {
$sMentionTemplate = self::GetMentionsTemplate($sInputElementId);
$oPage->add($sMentionTemplate);
}
catch(Exception $e){
} catch (Exception $e) {
ExceptionLog::LogException($e);
}
}
@@ -193,12 +190,11 @@ class CKEditorHelper
public static function ConfigureCKEditorElementForRenderingOutput(RenderingOutput $oOutput, string $sInputElementId, string $sInitialValue = null, bool $bWithMentions = false, bool $bAddJSFiles = true, array $aOverloadConfiguration = []): void
{
// link CKEditor JS files
if($bAddJSFiles){
if ($bAddJSFiles) {
foreach (static::GetJSFilesRelPathsForCKEditor() as $sFile) {
try{
try {
$oOutput->AddJsFile($sFile);
}
catch(Exception $e){
} catch (Exception $e) {
ExceptionLog::LogException($e);
}
}
@@ -212,12 +208,11 @@ class CKEditorHelper
$oOutput->AddJs("CombodoCKEditorHandler.CreateInstance('#$sInputElementId', $sConfigJS)");
// mentions template
if($bWithMentions){
try{
if ($bWithMentions) {
try {
$sMentionTemplate = self::GetMentionsTemplate($sInputElementId);
$oOutput->add($sMentionTemplate);
}
catch(Exception $e){
} catch (Exception $e) {
ExceptionLog::LogException($e);
}
}
@@ -256,7 +251,7 @@ HTML;
'node_modules/ckeditor5-itop-build/build/ckeditor.js',
'js/highlight/highlight.min.js',
'js/ckeditor.handler.js',
'js/ckeditor.feeds.js'
'js/ckeditor.feeds.js',
];
// add CKEditor translations resource
@@ -267,13 +262,12 @@ HTML;
// add corresponding ckeditor language file
// P1 language + country
// P2 language
$sLanguageFileRelPath = 'node_modules/ckeditor5-itop-build/build/translations/' . $sLanguage . '-' . $sCountry . '.js';
if(file_exists(APPROOT . $sLanguageFileRelPath)){
$sLanguageFileRelPath = 'node_modules/ckeditor5-itop-build/build/translations/'.$sLanguage.'-'.$sCountry.'.js';
if (file_exists(APPROOT.$sLanguageFileRelPath)) {
$aJSRelPaths[] = $sLanguageFileRelPath;
}
else {
$sLanguageFileRelPath = 'node_modules/ckeditor5-itop-build/build/translations/' . $sLanguage . '.js';
if(file_exists(APPROOT . $sLanguageFileRelPath)){
} else {
$sLanguageFileRelPath = 'node_modules/ckeditor5-itop-build/build/translations/'.$sLanguage.'.js';
if (file_exists(APPROOT.$sLanguageFileRelPath)) {
$aJSRelPaths[] = $sLanguageFileRelPath;
}
}
@@ -288,26 +282,26 @@ HTML;
* @throws \ConfigException
* @throws \CoreException
*/
public static function GetDOMSanitizerForCKEditor(DOMSanitizer $oSanitizer = null) : array
public static function GetDOMSanitizerForCKEditor(DOMSanitizer $oSanitizer = null): array
{
if($oSanitizer === null) {
if ($oSanitizer === null) {
/* @var $oSanitizer DOMSanitizer */
$sSanitizerClass = utils::GetConfig()->Get('html_sanitizer');
$oSanitizer = new $sSanitizerClass();
}
$aWhitelist = [
'allow' => [],
'disallow' => []
'disallow' => [],
];
// Build the allow list
foreach ($oSanitizer->GetTagsWhiteList() as $sTag => $aAttributes) {
$aAllowedItem = [
'name' => $sTag,
'attributes' => [],
'classes' => false,
'styles' => false
'styles' => false,
];
foreach ($aAttributes as $aAttr) {
@@ -317,7 +311,7 @@ HTML;
$aAllowedItem['classes'] = true;
} elseif (isset($oSanitizer->GetAttrsWhiteList()[$aAttr])) {
$aAllowedItem['attributes'][$aAttr] = [
'pattern' => $oSanitizer->GetAttrsWhiteList()[$aAttr]
'pattern' => $oSanitizer->GetAttrsWhiteList()[$aAttr],
];
} else {
$aAllowedItem['attributes'][$aAttr] = true;
@@ -339,7 +333,7 @@ HTML;
];
foreach ($oSanitizer->GetAttrsBlackList() as $aAttr) {
$aDisallowedItem['attributes'][$aAttr] = true;
$aDisallowedItem['attributes'][$aAttr] = true;
}
if (empty($aDisallowedItem['attributes'])) {
@@ -348,7 +342,7 @@ HTML;
$aWhitelist['disallow'][] = $aDisallowedItem;
}
return $aWhitelist;
}
}
}

View File

@@ -1,6 +1,7 @@
<?php
namespace Combodo\iTop\Application\Helper;
use Combodo\iTop\Application\UI\Base\Component\Alert\AlertUIBlockFactory;
use Dict;
use utils;
@@ -24,4 +25,4 @@ class ExportHelper
->SetIsClosable(false);
return $oAlert;
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/*
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
@@ -41,7 +42,6 @@ class FormHelper
*/
public const ENUM_MANDATORY_BLOB_MODE_MODIFY_FILLED = 'Modify:Filled';
/**
* DisableAttributeBlobInputs.
*
@@ -69,7 +69,7 @@ class FormHelper
// Set attribute blobs in read only
if ($oAttDef instanceof AttributeBlob) {
$aExtraParams['fieldsFlags'][$sAttCode] = OPT_ATT_READONLY;
$aExtraParams['fieldsComments'][$sAttCode] = '&nbsp;<img src="' . $sAppRootUrl . 'images/transp-lock.png" style="vertical-align:middle" title="'.utils::EscapeHtml(Dict::S('UI:UploadNotSupportedInThisMode')).'"/>';
$aExtraParams['fieldsComments'][$sAttCode] = '&nbsp;<img src="'.$sAppRootUrl.'images/transp-lock.png" style="vertical-align:middle" title="'.utils::EscapeHtml(Dict::S('UI:UploadNotSupportedInThisMode')).'"/>';
}
}
}
@@ -93,12 +93,12 @@ class FormHelper
}
return null;
}
/**
* Returns true if the object has a mandatory attribute blob
*
*
* @see N°6861 - Display warning when creating/editing a mandatory blob in modal
*
*
* @param \DBObject $oObject
*
* @return bool
@@ -111,7 +111,7 @@ class FormHelper
/**
* Returns an Alert explaining what will happen when a mandatory attribute blob is displayed in a form
*
*
* @see N°6861 - Display warning when creating/editing a mandatory blob in modal
* @see self::ENUM_MANDATORY_BLOB_MODE_XXX
*
@@ -122,19 +122,19 @@ class FormHelper
public static function GetAlertForMandatoryAttributeBlobInputsInModal(string $sMode = self::ENUM_MANDATORY_BLOB_MODE_MODIFY_EMPTY): Alert
{
$sMessage = Dict::S('UI:Object:Modal:'.$sMode.':MandatoryAttributeBlobInputs:Warning:Text');
// If the mandatory attribute is already filled, there's no risk to make an object incomplete so we display an information level alert
if($sMode === self::ENUM_MANDATORY_BLOB_MODE_MODIFY_FILLED){
if ($sMode === self::ENUM_MANDATORY_BLOB_MODE_MODIFY_FILLED) {
return AlertUIBlockFactory::MakeForInformation('', $sMessage);
}
return AlertUIBlockFactory::MakeForWarning('', $sMessage);
}
/**
* Update flags to be sent to form with url parameters
* For now only supports "readonly" param
*
*
* @param \DBObject $oObject
* @param array $aExtraParams
*
@@ -145,21 +145,21 @@ class FormHelper
{
$aRawValues = utils::ReadParam('readonly', [], '', 'raw_data');
$sObjectClass = get_class($oObject);
if(array_key_exists('fieldsFlags', $aExtraParams) === false ) {
if (array_key_exists('fieldsFlags', $aExtraParams) === false) {
$aExtraParams['fieldsFlags'] = [];
}
if(array_key_exists('forceFieldsSubmission', $aExtraParams) === false ) {
}
if (array_key_exists('forceFieldsSubmission', $aExtraParams) === false) {
$aExtraParams['forceFieldsSubmission'] = [];
}
// - For each attribute present in readonly array in url, add a flag and mark them as to be submitted with their default value
foreach($aRawValues as $sAttCode => $sValue) {
if(MetaModel::IsValidAttCode($sObjectClass, $sAttCode)) {
foreach ($aRawValues as $sAttCode => $sValue) {
if (MetaModel::IsValidAttCode($sObjectClass, $sAttCode)) {
$aExtraParams['fieldsFlags'][$sAttCode] = array_key_exists($sAttCode, $aExtraParams['fieldsFlags']) ?
$aExtraParams['fieldsFlags'][$sAttCode] & OPT_ATT_READONLY :
OPT_ATT_READONLY;
$aExtraParams['forceFieldsSubmission'][] = $sAttCode;
}
}
@@ -167,14 +167,15 @@ class FormHelper
/**
* Get attribute flag for an object allowing to cross-check with extra flags present in a form
*
*
* @param \DBObject $oObject
* @param string $sAttCode
* @param array $aExtraFlags
*
* @return int
*/
public static function GetAttributeFlagsForObject(DBObject $oObject, string $sAttCode, array $aExtraFlags = []): int {
public static function GetAttributeFlagsForObject(DBObject $oObject, string $sAttCode, array $aExtraFlags = []): int
{
$iFlags = $oObject->GetFormAttributeFlags($sAttCode);
if (array_key_exists($sAttCode, $aExtraFlags)) {
// the caller may override some flags if needed
@@ -182,4 +183,4 @@ class FormHelper
}
return $iFlags;
}
}
}

View File

@@ -1,10 +1,10 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\Helper;
use Combodo\iTop\SessionTracker\SessionHandler;

View File

@@ -1,4 +1,5 @@
<?php
/*
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
@@ -74,7 +75,6 @@ class WebResourcesHelper
return CKEditorHelper::GetJSFilesRelPathsForCKEditor();
}
//---------------------------------
// D3/C3.js
//---------------------------------
@@ -140,4 +140,4 @@ class WebResourcesHelper
$oPage->LinkScriptFromAppRoot('js/jquery.mousewheel.js');
$oPage->LinkScriptFromAppRoot('js/simple_graph.js');
}
}
}