#10676 Fix truncate text

This commit is contained in:
miguel angel rasteu 2023-09-11 10:09:34 +02:00
parent 9cdc7273a6
commit 99f92b9bec
5 changed files with 62 additions and 35 deletions

View File

@ -1025,6 +1025,27 @@ $table_font->data[$row][] = html_print_label_input_block(
); );
$row++; $row++;
$table_font->data[$row][] = html_print_label_input_block(
__('Truncate agent text at end'),
html_print_checkbox_switch(
'truncate_agent_at_end',
1,
$config['truncate_agent_at_end'],
true
)
);
$table_font->data[$row][] = html_print_label_input_block(
__('Truncate module text at end'),
html_print_checkbox_switch(
'truncate_module_at_end',
1,
$config['truncate_module_at_end'],
true
)
);
$row++;
$table_font->data[$row][] = html_print_label_input_block( $table_font->data[$row][] = html_print_label_input_block(
__('Agent size text'), __('Agent size text'),
html_print_div( html_print_div(

View File

@ -1288,6 +1288,10 @@ function config_update_config()
$error_update[] = __('Default line menu items for the Services'); $error_update[] = __('Default line menu items for the Services');
} }
if (config_update_value('truncate_agent_at_end', get_parameter('truncate_agent_at_end'), true) === false) {
$error_update[] = __('Truncate agent text at end');
}
if (config_update_value('agent_size_text_small', get_parameter('agent_size_text_small'), true) === false) { if (config_update_value('agent_size_text_small', get_parameter('agent_size_text_small'), true) === false) {
$error_update[] = __('Agent size text'); $error_update[] = __('Agent size text');
} }
@ -1296,6 +1300,10 @@ function config_update_config()
$error_update[] = __('Agent size text'); $error_update[] = __('Agent size text');
} }
if (config_update_value('truncate_module_at_end', get_parameter('truncate_module_at_end'), true) === false) {
$error_update[] = __('Truncate module text at end');
}
if (config_update_value('module_size_text_small', get_parameter('module_size_text_small'), true) === false) { if (config_update_value('module_size_text_small', get_parameter('module_size_text_small'), true) === false) {
$error_update[] = __('Module size text'); $error_update[] = __('Module size text');
} }
@ -3526,6 +3534,10 @@ function config_process_config()
config_update_value('display_item_frame', 1); config_update_value('display_item_frame', 1);
} }
if (!isset($config['truncate_agent_at_end'])) {
config_update_value('truncate_agent_at_end', 0);
}
if (!isset($config['agent_size_text_small'])) { if (!isset($config['agent_size_text_small'])) {
config_update_value('agent_size_text_small', 18); config_update_value('agent_size_text_small', 18);
} }
@ -3534,6 +3546,10 @@ function config_process_config()
config_update_value('agent_size_text_medium', 50); config_update_value('agent_size_text_medium', 50);
} }
if (!isset($config['truncate_module_at_end'])) {
config_update_value('truncate_module_at_end', 0);
}
if (!isset($config['module_size_text_small'])) { if (!isset($config['module_size_text_small'])) {
config_update_value('module_size_text_small', 25); config_update_value('module_size_text_small', 25);
} }

View File

@ -104,23 +104,22 @@ function ui_print_truncate_text(
switch ($numChars) { switch ($numChars) {
case 'agent_small': case 'agent_small':
$numChars = $config['agent_size_text_small']; $numChars = $config['agent_size_text_small'];
break; $truncate_at_end = (bool) $config['truncate_agent_at_end'];
case 'truncate_at_end':
$numChars = 28;
$truncate_at_end = true;
break; break;
case 'agent_medium': case 'agent_medium':
$numChars = $config['agent_size_text_medium']; $numChars = $config['agent_size_text_medium'];
$truncate_at_end = (bool) $config['truncate_agent_at_end'];
break; break;
case 'module_small': case 'module_small':
$numChars = $config['module_size_text_small']; $numChars = $config['module_size_text_small'];
$truncate_at_end = (bool) $config['truncate_module_at_end'];
break; break;
case 'module_medium': case 'module_medium':
$numChars = $config['module_size_text_medium']; $numChars = $config['module_size_text_medium'];
$truncate_at_end = (bool) $config['truncate_module_at_end'];
break; break;
case 'description': case 'description':
@ -154,8 +153,10 @@ function ui_print_truncate_text(
if ($truncate_at_end === true) { if ($truncate_at_end === true) {
// Recover the html entities to avoid XSS attacks. // Recover the html entities to avoid XSS attacks.
$truncateText = ($text_has_entities) ? io_safe_input(substr($text_html_decoded, 0, $numChars)) : $text_html_decoded; $truncateText = ($text_has_entities) ? io_safe_input(substr($text_html_decoded, 0, $numChars)) : substr($text_html_decoded, 0, $numChars);
if (strlen($text_html_decoded) > $numChars) {
$truncateText .= '...'; $truncateText .= '...';
}
} else { } else {
// Depending on the strange behavior of mb_strimwidth() itself, // Depending on the strange behavior of mb_strimwidth() itself,
// the 3rd parameter is not to be $numChars but the length of // the 3rd parameter is not to be $numChars but the length of

View File

@ -1729,7 +1729,7 @@ if (empty($result) === false) {
$agent_alias = ui_print_truncate_text( $agent_alias = ui_print_truncate_text(
$agent_alias, $agent_alias,
'truncate_at_end', 'agent_small',
false, false,
true, true,
true, true,
@ -1743,7 +1743,7 @@ if (empty($result) === false) {
} }
} else { } else {
$data[1] = '<strong><a href="index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$row['id_agent'].'">'; $data[1] = '<strong><a href="index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$row['id_agent'].'">';
$data[1] .= ui_print_truncate_text($agent_alias, 'agent_at_end', false, true, false, '[&hellip;]', 'font-size:7.5pt;'); $data[1] .= ui_print_truncate_text($agent_alias, 'agent_medium', false, true, false, '[&hellip;]', 'font-size:7.5pt;');
$data[1] .= '</a></strong>'; $data[1] .= '</a></strong>';
} }
} }

View File

@ -523,20 +523,12 @@ if (is_ajax() === true) {
} }
if (empty($tmp->module_name) === false) { if (empty($tmp->module_name) === false) {
$tmp->module_name = io_safe_output($tmp->module_name);
if (strlen($tmp->module_name) >= 20) {
$tmp->module_name = ui_print_truncate_text( $tmp->module_name = ui_print_truncate_text(
$tmp->module_name, $tmp->module_name,
20, 'module_medium',
false,
true,
false,
'&hellip;',
true,
true, true,
); );
} }
}
if (empty($tmp->comments) === false) { if (empty($tmp->comments) === false) {
$tmp->comments = ui_print_comments($tmp->comments, 20); $tmp->comments = ui_print_comments($tmp->comments, 20);
@ -564,11 +556,9 @@ if (is_ajax() === true) {
} }
} }
$tmp->agent_name = io_safe_output($tmp->agent_name);
if (strlen($tmp->agent_name) >= 10) {
$tmp->agent_name = ui_print_truncate_text( $tmp->agent_name = ui_print_truncate_text(
$tmp->agent_name, $tmp->agent_name,
10, 'agent_small',
false, false,
true, true,
false, false,
@ -576,7 +566,6 @@ if (is_ajax() === true) {
true, true,
true, true,
); );
}
$tmp->id_extra = io_safe_output($tmp->id_extra); $tmp->id_extra = io_safe_output($tmp->id_extra);
if (strlen($tmp->id_extra) >= 10) { if (strlen($tmp->id_extra) >= 10) {