diff --git a/inc/WPUBaseToolbox/WPUBaseToolbox.php b/inc/WPUBaseToolbox/WPUBaseToolbox.php
index 5d3ed1b..15ac84e 100644
--- a/inc/WPUBaseToolbox/WPUBaseToolbox.php
+++ b/inc/WPUBaseToolbox/WPUBaseToolbox.php
@@ -4,7 +4,7 @@
/*
Class Name: WPU Base Toolbox
Description: Cool helpers for WordPress Plugins
-Version: 0.12.0
+Version: 0.12.1
Class URI: https://github.com/WordPressUtilities/wpubaseplugin
Author: Darklg
Author URI: https://darklg.me/
@@ -15,7 +15,7 @@
defined('ABSPATH') || die;
class WPUBaseToolbox {
- private $plugin_version = '0.12.0';
+ private $plugin_version = '0.12.1';
public function __construct() {
add_action('wp_enqueue_scripts', array(&$this,
'form_scripts'
@@ -405,6 +405,8 @@ function array_to_html_table($array, $args = array()) {
/* Fix args */
$default_args = array(
'table_classname' => 'widefat',
+ 'htmlspecialchars_td' => true,
+ 'htmlspecialchars_th' => true,
'colnames' => array()
);
if (!is_array($args)) {
@@ -421,7 +423,10 @@ function array_to_html_table($array, $args = array()) {
if (isset($args['colnames'][$key])) {
$label = $args['colnames'][$key];
}
- $html .= '
' . htmlspecialchars($label) . ' | ';
+ if ($args['htmlspecialchars_th']) {
+ $label = htmlspecialchars($label);
+ }
+ $html .= '' . $label . ' | ';
}
$html .= '';
@@ -430,7 +435,10 @@ function array_to_html_table($array, $args = array()) {
foreach ($array as $line) {
$html .= '';
foreach ($line as $value) {
- $html .= '' . htmlspecialchars($value) . ' | ';
+ if ($args['htmlspecialchars_td']) {
+ $value = htmlspecialchars($value);
+ }
+ $html .= '' . $value . ' | ';
}
$html .= '
';
}
diff --git a/lang/wpuerrorlogs-fr_FR.mo b/lang/wpuerrorlogs-fr_FR.mo
index b15b2e6..5d60116 100644
Binary files a/lang/wpuerrorlogs-fr_FR.mo and b/lang/wpuerrorlogs-fr_FR.mo differ
diff --git a/lang/wpuerrorlogs-fr_FR.po b/lang/wpuerrorlogs-fr_FR.po
index cfe8e73..03944cc 100644
--- a/lang/wpuerrorlogs-fr_FR.po
+++ b/lang/wpuerrorlogs-fr_FR.po
@@ -1,7 +1,7 @@
msgid ""
msgstr ""
"Project-Id-Version: WPU Error Logs\n"
-"POT-Creation-Date: 2024-02-20 23:00+0700\n"
+"POT-Creation-Date: 2024-02-25 21:31+0100\n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language-Team: \n"
@@ -28,30 +28,34 @@ msgstr "Réglages"
msgid "Import Settings"
msgstr "Paramètres d'importation"
-#: wpuerrorlogs.php:144
+#: wpuerrorlogs.php:150
msgid "Count"
msgstr "Nombre"
-#: wpuerrorlogs.php:145
+#: wpuerrorlogs.php:151
msgid "Date"
msgstr "Date"
-#: wpuerrorlogs.php:146
+#: wpuerrorlogs.php:152
msgid "Type"
msgstr "Type"
-#: wpuerrorlogs.php:147
+#: wpuerrorlogs.php:153
msgid "Text"
msgstr "Texte"
-#: wpuerrorlogs.php:152
+#: wpuerrorlogs.php:158
msgid "Top errors"
msgstr "Principales erreurs"
-#: wpuerrorlogs.php:157 wpuerrorlogs.php:166
+#: wpuerrorlogs.php:164 wpuerrorlogs.php:174
msgid "No errors at the moment."
msgstr "Pas d’erreurs pour le moment."
-#: wpuerrorlogs.php:161
+#: wpuerrorlogs.php:168
msgid "Latest errors"
msgstr "Dernières erreurs"
+
+#: wpuerrorlogs.php:338
+msgid "Full error"
+msgstr "Erreur complète"
diff --git a/wpuerrorlogs.php b/wpuerrorlogs.php
index ce150d3..c63483d 100644
--- a/wpuerrorlogs.php
+++ b/wpuerrorlogs.php
@@ -4,7 +4,7 @@
Plugin URI: https://github.com/WordPressUtilities/wpuerrorlogs
Update URI: https://github.com/WordPressUtilities/wpuerrorlogs
Description: Make sense of your log files
-Version: 0.2.1
+Version: 0.3.0
Author: Darklg
Author URI: https://github.com/Darklg
Text Domain: wpuerrorlogs
@@ -20,7 +20,7 @@
}
class WPUErrorLogs {
- private $plugin_version = '0.2.1';
+ private $plugin_version = '0.3.0';
private $plugin_settings = array(
'id' => 'wpuerrorlogs',
'name' => 'WPU Error Logs'
@@ -139,6 +139,12 @@ public function page_content__main() {
$errors = $this->get_logs();
+ /* Prepare for display */
+ $errors = array_map(function ($item) {
+ $item['text'] = $this->display_content_with_toggle($item['text']);
+ return $item;
+ }, $errors);
+
/* Keep only first five and extract data */
$colnames = array(
'count' => __('Count', 'wpuerrorlogs'),
@@ -151,7 +157,8 @@ public function page_content__main() {
$top_errors = $this->sort_errors_by_top($errors, 10);
echo '' . __('Top errors', 'wpuerrorlogs') . '
';
$html_errors = $this->basetoolbox->array_to_html_table($top_errors, array(
- 'table_classname' => 'widefat',
+ 'table_classname' => 'widefat striped',
+ 'htmlspecialchars_td' => false,
'colnames' => $colnames
));
echo $html_errors ? $html_errors : '' . __('No errors at the moment.', 'wpuerrorlogs') . '
';
@@ -160,7 +167,8 @@ public function page_content__main() {
$latest_errors = $this->sort_errors_by_latest($errors, 10);
echo '' . __('Latest errors', 'wpuerrorlogs') . '
';
$html_errors = $this->basetoolbox->array_to_html_table($latest_errors, array(
- 'table_classname' => 'widefat',
+ 'table_classname' => 'widefat striped',
+ 'htmlspecialchars_td' => false,
'colnames' => $colnames
));
echo $html_errors ? $html_errors : '' . __('No errors at the moment.', 'wpuerrorlogs') . '
';
@@ -216,29 +224,34 @@ function get_logs() {
}
$errors = $this->get_logs_from_file($file);
- $previous_file = $this->find_previous_log_file($file);
- if ($previous_file) {
+ $previous_files = $this->find_previous_log_files($file, 5);
+ foreach ($previous_files as $previous_file) {
$errors_previous = $this->get_logs_from_file($previous_file);
- $errors = $errors + $errors_previous;
+ foreach ($errors_previous as $error) {
+ $errors[] = $error;
+ }
}
return $errors;
}
- function find_previous_log_file($file) {
+ function find_previous_log_files($file, $number_of_days = 5) {
$date_formats = array('Ymd', 'dmY');
+ $previous_files = array();
foreach ($date_formats as $date_format) {
$now_date = date($date_format);
if (strpos($file, $now_date) === false) {
continue;
}
- $previous_date = date($date_format, time() - 86400);
- $previous_file = str_replace($now_date, $previous_date, $file);
- if (is_readable($previous_file)) {
- return $previous_file;
+ for ($i = 1; $i <= $number_of_days; $i++) {
+ $previous_date = date($date_format, time() - 86400 * $i);
+ $previous_file = str_replace($now_date, $previous_date, $file);
+ if (is_readable($previous_file)) {
+ $previous_files[] = $previous_file;
+ }
}
}
- return false;
+ return $previous_files;
}
function get_logs_from_file($file) {
@@ -269,7 +282,6 @@ function get_logs_from_file($file) {
$currentError['text'] = $this->minimize_error_text($currentError['text']);
$errors[] = $currentError;
}
-
return $errors;
}
@@ -277,7 +289,7 @@ function get_error_from_line($line) {
/* Extract values */
$date_parts = explode(']', $line);
$date = str_replace('[', '', $date_parts[0]);
- $text = trim(substr($line, strlen('[' . $date . ']'), -1));
+ $text = trim(substr($line, strlen('[' . $date . ']')));
/* Extract type */
$type = 'none';
@@ -310,6 +322,26 @@ function get_error_from_line($line) {
Helpers
---------------------------------------------------------- */
+ /* Display content
+ -------------------------- */
+
+ function display_content_with_toggle($content) {
+ $content = strip_tags($content);
+ if (strpos($content, "\n") === false) {
+ return $content;
+ }
+ $content_parts = explode("\n", $content);
+ if (!isset($content_parts[1])) {
+ return $content;
+ }
+ $content = $content_parts[0];
+ $content .= '' . __('Full error', 'wpuerrorlogs') . '
' . implode("\n", $content_parts) . '
';
+ return $content;
+ }
+
+ /* Minimize text
+ -------------------------- */
+
function minimize_get_correspondances() {
return array(
'abs' => ABSPATH,