Commit 01d8260f authored by Michael Iseard's avatar Michael Iseard
Browse files

Add ellipsis to message/context if longer than 255 chars

parent 5874621a
...@@ -292,4 +292,19 @@ class Utils { ...@@ -292,4 +292,19 @@ class Utils {
return $image_url; return $image_url;
} }
/**
* Truncates string at specified length and return with ellipsis
* if longer.
*
* @param string $string
* @param int $length
*
* @return string
*/
public static function truncate_string(string $string, int $length): string {
return strlen($string) > $length ? substr($string, 0, $length) . "..." : $string;
}
} }
<?php <?php
use Kudos\Helpers\Utils;
use Kudos\Service\LoggerService; use Kudos\Service\LoggerService;
/** /**
...@@ -93,10 +94,10 @@ $tab = $_GET['tab'] ?? $default_tab; ...@@ -93,10 +94,10 @@ $tab = $_GET['tab'] ?? $default_tab;
<?php echo esc_attr( $level ); ?> <?php echo esc_attr( $level ); ?>
</td> </td>
<td title="<?php echo( $message ); ?>"> <td title="<?php echo( $message ); ?>">
<?php echo( substr( $message, 0, 255 ) ); ?> <?php echo( Utils::truncate_string($message, 255) ); ?>
</td> </td>
<td title="<?php echo( $context ); ?>"> <td title="<?php echo( $context ); ?>">
<?php echo( substr( $context, 0, 255 ) ); ?> <?php echo( Utils::truncate_string($context, 255) ); ?>
</td> </td>
</tr> </tr>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment