Skip to content

Commit

Permalink
v 0.6.0
Browse files Browse the repository at this point in the history
- Hook for number of days.
- User can choose the number of days displayed.
- Better memory use.
- Update dependencies.
  • Loading branch information
Darklg committed Apr 16, 2024
1 parent 317b1c5 commit c0582f8
Show file tree
Hide file tree
Showing 9 changed files with 221 additions and 33 deletions.
13 changes: 11 additions & 2 deletions inc/WPUBaseAdminPage/WPUBaseAdminPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/*
Class Name: WPU Base Admin page
Description: A class to handle pages in WordPress
Version: 1.6.0
Version: 1.7.0
Class URI: https://github.com/WordPressUtilities/wpubaseplugin
Author: Darklg
Author URI: https://darklg.me/
Expand Down Expand Up @@ -238,11 +238,13 @@ public function add_settings_link($links) {
public function set_admin_page_main() {
$page = $this->get_page();

$form_classname = $this->prefix . $page . '-form';

echo $this->get_wrapper_start();

// Default Form
if ($this->pages[$page]['has_form']):
echo '<form action="' . admin_url('admin-post.php') . '" method="post" ' . ($this->pages[$page]['has_file'] ? ' enctype="multipart/form-data"' : '') . '><div>';
echo '<form class="' . esc_attr($form_classname) . '" action="' . admin_url('admin-post.php') . '" method="post" ' . ($this->pages[$page]['has_file'] ? ' enctype="multipart/form-data"' : '') . '><div>';
echo '<input type="hidden" name="action" value="' . $this->options['id'] . '">';
echo '<input type="hidden" name="page_name" value="' . $page . '" />';
wp_nonce_field('action-main-form-' . $page, 'action-main-form-' . $this->options['id'] . '-' . $page);
Expand Down Expand Up @@ -283,4 +285,11 @@ private function get_page() {
}
return $page;
}

public function get_page_url($page_id){
if(!isset($this->pages[$page_id])){
return false;
}
return $this->pages[$page_id]['url'];
}
}
6 changes: 4 additions & 2 deletions inc/WPUBaseToolbox/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ Cool helpers for WordPress Plugins.
## Insert in the INIT hook

```php
require_once dirname(__FILE__) . '/inc/WPUBaseToolbox/WPUBaseToolbox.php';
$this->basetoolbox = new \myplugin\WPUBaseToolbox();
require_once __DIR__ . '/inc/WPUBaseToolbox/WPUBaseToolbox.php';
$this->basetoolbox = new \myplugin\WPUBaseToolbox(array(
'need_form_js' => false
));
```

## Use functions
Expand Down
127 changes: 123 additions & 4 deletions inc/WPUBaseToolbox/WPUBaseToolbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/*
Class Name: WPU Base Toolbox
Description: Cool helpers for WordPress Plugins
Version: 0.12.1
Version: 0.14.0
Class URI: https://github.com/WordPressUtilities/wpubaseplugin
Author: Darklg
Author URI: https://darklg.me/
Expand All @@ -15,15 +15,27 @@
defined('ABSPATH') || die;

class WPUBaseToolbox {
private $plugin_version = '0.12.1';
public function __construct() {
private $plugin_version = '0.14.0';
private $args = array();
private $default_module_args = array(
'need_form_js' => true
);

public function __construct($args = array()) {
if (!is_array($args)) {
$args = array();
}
$this->args = array_merge($this->default_module_args, $args);

add_action('wp_enqueue_scripts', array(&$this,
'form_scripts'
));
}

function form_scripts() {
wp_enqueue_script(__NAMESPACE__ . '-wpubasetoolbox-form-validation', plugins_url('assets/form-validation.js', __FILE__), array(), $this->plugin_version);
if ($this->args['need_form_js']) {
wp_enqueue_script(__NAMESPACE__ . '-wpubasetoolbox-form-validation', plugins_url('assets/form-validation.js', __FILE__), array(), $this->plugin_version);
}
}

/* ----------------------------------------------------------
Expand Down Expand Up @@ -449,4 +461,111 @@ function array_to_html_table($array, $args = array()) {
return $html;
}

/* ----------------------------------------------------------
Export
---------------------------------------------------------- */

/* Ensure all lines have the same keys
-------------------------- */

function export_array_clean_for_csv($data) {

/* Extract all available keys */
$all_keys = array();
foreach ($data as $item) {
$all_keys = array_merge($all_keys, array_keys($item));
}
$all_keys = array_unique($all_keys);

foreach ($data as $item_key => $item) {
/* Ensure all rows have the same keys */
foreach ($all_keys as $k) {
if (!isset($item[$k])) {
$data[$item_key][$k] = '';
}
}
/* Ensure same sorting of all keys */
ksort($data[$item_key]);
}

return $data;
}

/* Array to JSON
-------------------------- */

public function export_array_to_json($data, $name) {
if (!isset($data[0])) {
return;
}
/* Correct headers */
header('Content-type: application/json');
header('Content-Disposition: attachment; filename=' . $name . '.json');
header('Pragma: no-cache');

echo json_encode($data);
}

/* Array to CSV
-------------------------- */

public function export_array_to_csv($data, $name) {
if (!isset($data[0])) {
return;
}

$data = $this->export_array_clean_for_csv($data);

/* Correct headers */
header('Content-Type: application/csv');
header('Content-Disposition: attachment; filename=' . $name . '.csv');
header('Pragma: no-cache');

$all_keys = array_keys($data[0]);

/* Build and send CSV */
$output = fopen("php://output", 'w');
fputcsv($output, $all_keys);
foreach ($data as $item) {
fputcsv($output, $item);
}
fclose($output);
die;
}

/* ----------------------------------------------------------
IPs
---------------------------------------------------------- */

/* Thanks to https://stackoverflow.com/a/13646735/975337 */
function get_user_ip($anonymized = true) {
if (isset($_SERVER["HTTP_CF_CONNECTING_IP"])) {
$_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_CF_CONNECTING_IP"];
$_SERVER['HTTP_CLIENT_IP'] = $_SERVER["HTTP_CF_CONNECTING_IP"];
}
$client = isset($_SERVER['HTTP_CLIENT_IP']) ? $_SERVER['HTTP_CLIENT_IP'] : '';
$forward = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : '';
$remote = $_SERVER['REMOTE_ADDR'];

if (filter_var($client, FILTER_VALIDATE_IP)) {
$ip = $client;
} elseif (filter_var($forward, FILTER_VALIDATE_IP)) {
$ip = $forward;
} else {
$ip = $remote;
}
if (!$anonymized) {
return $ip;
}
return $this->anonymize_ip($ip);
}

/* Thanks to https://gist.github.com/svrnm/3a124d2af18a6726f66e */
function anonymize_ip($ip) {
if ($ip = @inet_pton($ip)) {
return inet_ntop(substr($ip, 0, strlen($ip) / 2) . str_repeat(chr(0), strlen($ip) / 2));
}
return '0.0.0.0';
}

}
1 change: 1 addition & 0 deletions inc/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php /* Silence */
1 change: 1 addition & 0 deletions lang/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
deny from all
1 change: 1 addition & 0 deletions lang/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php /* Silence */
Binary file modified lang/wpuerrorlogs-fr_FR.mo
Binary file not shown.
46 changes: 31 additions & 15 deletions lang/wpuerrorlogs-fr_FR.po
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
msgid ""
msgstr ""
"Project-Id-Version: WPU Error Logs\n"
"POT-Creation-Date: 2024-02-25 21:31+0100\n"
"POT-Creation-Date: 2024-04-16 22:55+0200\n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language-Team: \n"
Expand All @@ -11,51 +11,67 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-Basepath: ..\n"
"X-Poedit-KeywordsList: __;_x;_e\n"
"X-Poedit-KeywordsList: __;_x;_e;_n\n"
"X-Generator: Poedit 3.4.2\n"
"X-Poedit-SearchPath-0: .\n"
"X-Poedit-SearchPathExcluded-0: inc\n"

#: wpuerrorlogs.php:47
#: wpuerrorlogs.php:44
msgid "Make sense of your log files"
msgstr "Donnez un sens à vos fichiers logs"

#: wpuerrorlogs.php:61
#: wpuerrorlogs.php:64
msgid "Settings"
msgstr "Réglages"

#: wpuerrorlogs.php:102
msgid "Import Settings"
msgstr "Paramètres d'importation"

#: wpuerrorlogs.php:150
msgid "Count"
msgstr "Nombre"

#: wpuerrorlogs.php:151
#: wpuerrorlogs.php:103
msgid "Date"
msgstr "Date"

#: wpuerrorlogs.php:152
#: wpuerrorlogs.php:104
msgid "Type"
msgstr "Type"

#: wpuerrorlogs.php:153
#: wpuerrorlogs.php:105
msgid "Text"
msgstr "Texte"

#: wpuerrorlogs.php:158
#: wpuerrorlogs.php:109
msgid "Check the last :"
msgstr "Vérifiez les derniers :"

#: wpuerrorlogs.php:112
msgid "1 day"
msgstr "1 jour"

#: wpuerrorlogs.php:112
#, php-format
msgid "%s days"
msgstr "%s jours"

#: wpuerrorlogs.php:118
msgid "Top errors"
msgstr "Principales erreurs"

#: wpuerrorlogs.php:164 wpuerrorlogs.php:174
#: wpuerrorlogs.php:124 wpuerrorlogs.php:134
msgid "No errors at the moment."
msgstr "Pas d’erreurs pour le moment."

#: wpuerrorlogs.php:168
#: wpuerrorlogs.php:128
msgid "Latest errors"
msgstr "Dernières erreurs"

#: wpuerrorlogs.php:338
#: wpuerrorlogs.php:147
msgid "Latest fatal errors"
msgstr "Dernières erreurs fatales"

#: wpuerrorlogs.php:342
msgid "Full error"
msgstr "Erreur complète"

#~ msgid "Import Settings"
#~ msgstr "Paramètres d'importation"
Loading

0 comments on commit c0582f8

Please sign in to comment.