Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [UNRELEASED]

### Added

- Add psalm

### Fixed

- Fix massive action update on CustomAssets
Expand Down
6 changes: 3 additions & 3 deletions ajax/field_specific_fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
if ($type === 'glpi_item') {
// Display "allowed values" field
echo '<td>';
echo __('Allowed values', 'fields') . ' :';
echo __s('Allowed values', 'fields') . ' :';
echo '</td>';

echo '<td style="line-height:var(--tblr-body-line-height);">';
Expand Down Expand Up @@ -82,11 +82,11 @@
// Display "default value(s)" field
echo '<td>';
if ($is_dropdown_multi) {
echo __('Multiple dropdown', 'fields') . ' :';
echo __s('Multiple dropdown', 'fields') . ' :';
echo '<br />';
}

echo __('Default value', 'fields') . ' :';
echo __s('Default value', 'fields') . ' :';
if (in_array($type, ['date', 'datetime'])) {
echo '<i class="pointer fa fa-info" title="' . __s("You can use 'now' for date and datetime field") . '"></i>';
}
Expand Down
2 changes: 1 addition & 1 deletion ajax/viewtranslations.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@
if ($canedit) {
$translation->showFormForItem($_POST['itemtype'], $_POST['items_id'], $_POST['id']);
} else {
echo __('Access denied');
echo __s('Access denied');
}
63 changes: 34 additions & 29 deletions inc/container.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public static function canPurge(): bool
public static function titleList()
{
echo "<div class='center'><a class='vsubmit' href='regenerate_files.php'><i class='pointer fa fa-refresh'></i>&nbsp;"
. __('Regenerate container files', 'fields') . "</a>&nbsp;&nbsp;<a class='vsubmit' href='export_to_yaml.php'><i class='pointer fa fa-refresh'></i>&nbsp;"
. __('Export to YAML', 'fields') . '</a></div><br>';
. __s('Regenerate container files', 'fields') . "</a>&nbsp;&nbsp;<a class='vsubmit' href='export_to_yaml.php'><i class='pointer fa fa-refresh'></i>&nbsp;"
. __s('Export to YAML', 'fields') . '</a></div><br>';
}

public function getForbiddenStandardMassiveAction()
Expand Down Expand Up @@ -82,7 +82,7 @@ public static function installBaseData(Migration $migration, $version)
$table = self::getTable();

if (!$DB->tableExists($table)) {
$migration->displayMessage(sprintf(__('Installing %s'), $table));
$migration->displayMessage(sprintf(__s('Installing %s'), $table));

$query = "CREATE TABLE IF NOT EXISTS `{$table}` (
`id` INT {$default_key_sign} NOT NULL auto_increment,
Expand Down Expand Up @@ -269,7 +269,7 @@ public static function installUserData(Migration $migration, $version)
}

// Regenerate container classes to ensure they can be used
$migration->displayMessage(__('Regenerate containers files', 'fields'));
$migration->displayMessage(__s('Regenerate containers files', 'fields'));
$obj = new self();
$containers = $obj->find();
foreach ($containers as $container) {
Expand All @@ -290,7 +290,7 @@ public static function installUserData(Migration $migration, $version)
);

if ($bad_named_containers->count() > 0) {
$migration->displayMessage(__('Fix container names', 'fields'));
$migration->displayMessage(__s('Fix container names', 'fields'));

$toolbox = new PluginFieldsToolbox();

Expand Down Expand Up @@ -438,7 +438,7 @@ public static function installUserData(Migration $migration, $version)
$migration->executeMigration();

// Regenerate files and install missing tables
$migration->displayMessage(__('Updating generated containers files', 'fields'));
$migration->displayMessage(__s('Updating generated containers files', 'fields'));

$obj = new self();
$containers = $obj->find();
Expand Down Expand Up @@ -630,7 +630,7 @@ public function prepareInputForAdd($input)
{
if (empty($input['itemtypes'])) {
Session::AddMessageAfterRedirect(
__(
__s(
'You cannot add block without associated element type',
'fields',
),
Expand All @@ -652,7 +652,7 @@ public function prepareInputForAdd($input)
foreach (array_column($found, 'itemtypes') as $founditemtypes) {
foreach (PluginFieldsToolbox::decodeJSONItemtypes($founditemtypes) as $founditemtype) {
if (in_array($founditemtype, $input['itemtypes'])) {
Session::AddMessageAfterRedirect(__("You cannot add several blocks with type 'Insertion in the form' on same object", 'fields'), false, ERROR);
Session::AddMessageAfterRedirect(__s("You cannot add several blocks with type 'Insertion in the form' on same object", 'fields'), false, ERROR);

return false;
}
Expand All @@ -668,7 +668,7 @@ public function prepareInputForAdd($input)
foreach (array_column($found, 'itemtypes') as $founditemtypes) {
foreach (PluginFieldsToolbox::decodeJSONItemtypes($founditemtypes) as $founditemtype) {
if (in_array($founditemtype, $input['itemtypes'])) {
Session::AddMessageAfterRedirect(__("You cannot add several blocks with type 'Insertion in the form of a specific tab' on same object tab", 'fields'), false, ERROR);
Session::AddMessageAfterRedirect(__s("You cannot add several blocks with type 'Insertion in the form of a specific tab' on same object tab", 'fields'), false, ERROR);

return false;
}
Expand All @@ -679,7 +679,7 @@ public function prepareInputForAdd($input)
$accepted_itemtypes = array_keys(array_merge(...array_values(self::getItemtypes(true))));
foreach ($input['itemtypes'] as $itemtype) {
if (!in_array($itemtype, $accepted_itemtypes)) {
Session::AddMessageAfterRedirect(__("At least one selected object cannot be linked with type 'Insertion in the form of a specific tab'.", 'fields'), false, ERROR);
Session::AddMessageAfterRedirect(__s("At least one selected object cannot be linked with type 'Insertion in the form of a specific tab'.", 'fields'), false, ERROR);

return false;
}
Expand All @@ -693,7 +693,7 @@ public function prepareInputForAdd($input)
$tmp = getTableForItemType(self::getClassname($itemtype, $input['name']));
if (strlen($tmp) > 64) {
Session::AddMessageAfterRedirect(
__('Container name is too long for database (digits in name are replaced by characters, try to remove them)', 'fields'),
__s('Container name is too long for database (digits in name are replaced by characters, try to remove them)', 'fields'),
false,
ERROR,
);
Expand All @@ -708,7 +708,7 @@ public function prepareInputForAdd($input)
foreach (array_column($found, 'itemtypes') as $founditemtypes) {
foreach (PluginFieldsToolbox::decodeJSONItemtypes($founditemtypes) as $founditemtype) {
if (in_array($founditemtype, $input['itemtypes'])) {
Session::AddMessageAfterRedirect(__('You cannot add several blocs with identical name on same object', 'fields'), false, ERROR);
Session::AddMessageAfterRedirect(__s('You cannot add several blocs with identical name on same object', 'fields'), false, ERROR);

return false;
}
Expand Down Expand Up @@ -952,7 +952,7 @@ public function showForm($ID, $options = [])
$rand = mt_rand();

echo '<tr>';
echo "<td width='20%'>" . __('Label') . ' : </td>';
echo "<td width='20%'>" . __s('Label') . ' : </td>';
echo "<td width='30%'>";
echo Html::input(
'label',
Expand All @@ -966,7 +966,7 @@ public function showForm($ID, $options = [])
echo '</tr>';

echo '<tr>';
echo '<td>' . __('Type') . ' : </td>';
echo '<td>' . __s('Type') . ' : </td>';
echo '<td>';
if ($ID > 0) {
$types = self::getTypes();
Expand Down Expand Up @@ -994,7 +994,7 @@ public function showForm($ID, $options = [])
}

echo '</td>';
echo '<td>' . __('Associated item type') . ' : </td>';
echo '<td>' . __s('Associated item type') . ' : </td>';
echo '<td>';
if ($ID > 0) {
$types = PluginFieldsToolbox::decodeJSONItemtypes($this->fields['itemtypes']);
Expand Down Expand Up @@ -1039,7 +1039,7 @@ public function showForm($ID, $options = [])

echo sprintf("<tr id='tab_tr' %s>", $display);
echo "<td colspan='2'></td>";
echo '<td>' . __('Tab', 'fields') . ' : </td>';
echo '<td>' . __s('Tab', 'fields') . ' : </td>';
echo '<td>';
echo sprintf("&nbsp;<span id='subtype_%d'></span>", $rand);
if ($ID > 0 && !empty($this->fields['subtype'])) {
Expand All @@ -1056,7 +1056,7 @@ public function showForm($ID, $options = [])
echo '</tr>';

echo '<tr>';
echo '<td>' . __('Active') . ' : </td>';
echo '<td>' . __s('Active') . ' : </td>';
echo '<td>';
Dropdown::showYesNo('is_active', $this->fields['is_active']);
echo '</td>';
Expand Down Expand Up @@ -1198,9 +1198,9 @@ public static function getItemtypes($is_domtab)
public static function getTypes()
{
return [
'tab' => __('Add tab', 'fields'),
'dom' => __('Insertion in the form (before save button)', 'fields'),
'domtab' => __('Insertion in the form of a specific tab (before save button)', 'fields'),
'tab' => __s('Add tab', 'fields'),
'dom' => __s('Insertion in the form (before save button)', 'fields'),
'domtab' => __s('Insertion in the form of a specific tab (before save button)', 'fields'),
];
}

Expand Down Expand Up @@ -1734,17 +1734,17 @@ public static function validateValues($data, $itemtype, $massiveaction)
}

if ($empty_errors !== []) {
Session::AddMessageAfterRedirect(__('Some mandatory fields are empty', 'fields')
Session::AddMessageAfterRedirect(__s('Some mandatory fields are empty', 'fields')
. ' : ' . implode(', ', $empty_errors), false, ERROR);
}

if ($number_errors !== []) {
Session::AddMessageAfterRedirect(__('Some numeric fields contains non numeric values', 'fields')
Session::AddMessageAfterRedirect(__s('Some numeric fields contains non numeric values', 'fields')
. ' : ' . implode(', ', $number_errors), false, ERROR);
}

if ($url_errors !== []) {
Session::AddMessageAfterRedirect(__('Some URL fields contains invalid links', 'fields')
Session::AddMessageAfterRedirect(__s('Some URL fields contains invalid links', 'fields')
. ' : ' . implode(', ', $url_errors), false, ERROR);
}

Expand Down Expand Up @@ -2349,11 +2349,11 @@ private static function getSubtypes($item)
switch ($item::getType()) {
case Entity::getType():
$tabs = [
'Entity$2' => __('Address'),
'Entity$3' => __('Advanced information'),
'Entity$4' => __('Notifications'),
'Entity$5' => __('Assistance'),
'Entity$6' => __('Assets'),
'Entity$2' => __s('Address'),
'Entity$3' => __s('Advanced information'),
'Entity$4' => __s('Notifications'),
'Entity$5' => __s('Assistance'),
'Entity$6' => __s('Assets'),
];
break;
default:
Expand Down Expand Up @@ -2390,10 +2390,15 @@ public static function getClassname(string $itemtype, string $container_name, st
*
* @param string $itemtype Name of associated itemtype
* @param string $container_name Name of container
*
* @psalm-taint-escape file (only `[A-Za-z0-9_]` characters are kept, forcing path safeness)
*/
protected static function getSystemName(string $itemtype, string $container_name): string
{
return strtolower(str_replace('\\', '', $itemtype) . preg_replace('/s$/', '', $container_name));
// Only keep characters valid in a PHP class name, as the result is used to build filenames.
$itemtype = preg_replace('/[^A-Za-z0-9_]/', '', $itemtype);

return strtolower($itemtype . preg_replace('/s$/', '', $container_name));
}

public static function getIcon()
Expand Down
14 changes: 7 additions & 7 deletions inc/containerdisplaycondition.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static function installBaseData(Migration $migration, $version)
$table = self::getTable();

if (!$DB->tableExists($table)) {
$migration->displayMessage(sprintf(__('Installing %s'), $table));
$migration->displayMessage(sprintf(__s('Installing %s'), $table));
$query = "CREATE TABLE IF NOT EXISTS `{$table}` (
`id` INT {$default_key_sign} NOT NULL auto_increment,
`plugin_fields_containers_id` INT {$default_key_sign} NOT NULL DEFAULT '0',
Expand Down Expand Up @@ -132,13 +132,13 @@ public static function getConditionName($condition)
echo '>';
break;
case self::SHOW_CONDITION_REGEX:
echo __('regular expression matches', 'fields');
echo __s('regular expression matches', 'fields');
break;
case self::SHOW_CONDITION_UNDER:
echo __('under', 'fields');
echo __s('under', 'fields');
break;
case self::SHOW_CONDITION_NOT_UNDER:
echo __('not under', 'fields');
echo __s('not under', 'fields');
break;
}
}
Expand Down Expand Up @@ -359,7 +359,7 @@ public static function getRawValue($searchoption_id, $itemtype, $value)
$raw_value = $value;
}

echo $raw_value;
echo htmlescape($raw_value);
}

public static function removeBlackListedOption($array, $itemtype_class)
Expand Down Expand Up @@ -508,7 +508,7 @@ public function prepareInputForAdd($input)
// itemtype, search_option, condition, value must all be set
if (!isset($input['itemtype'], $input['search_option'], $input['condition'])) {
Session::addMessageAfterRedirect(
__('You must specify an item type, search option and condition.', 'fields'),
__s('You must specify an item type, search option and condition.', 'fields'),
true,
ERROR,
);
Expand All @@ -524,7 +524,7 @@ public function prepareInputForUpdate($input)
// itemtype, search_option, condition, value must all be set
if (!isset($input['itemtype'], $input['search_option'], $input['condition'])) {
Session::addMessageAfterRedirect(
__('You must specify an item type, search option and condition.', 'fields'),
__s('You must specify an item type, search option and condition.', 'fields'),
true,
ERROR,
);
Expand Down
2 changes: 1 addition & 1 deletion inc/dropdown.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static function installUserData(Migration $migration, $version)
$migration->executeMigration();

// Regenerate files and install missing tables
$migration->displayMessage(__('Updating generated dropdown files', 'fields'));
$migration->displayMessage(__s('Updating generated dropdown files', 'fields'));

$obj = new PluginFieldsField();
$fields = $obj->find(['type' => 'dropdown']);
Expand Down
Loading
Loading