| @@ -1,68 +1,105 @@ | ||
| 1 | +<?php | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * @package Logtivity | |
| 5 | + * @contact logtivity.io, [email protected] | |
| 6 | + * @copyright 2024-2026 Logtivity. All rights reserved | |
| 7 | + * @license https://www.gnu.org/licenses/gpl.html GNU/GPL | |
| 8 | + * | |
| 9 | + * This file is part of Logtivity. | |
| 10 | + * | |
| 11 | + * Logtivity is free software: you can redistribute it and/or modify | |
| 12 | + * it under the terms of the GNU General Public License as published by | |
| 13 | + * the Free Software Foundation, either version 2 of the License, or | |
| 14 | + * (at your option) any later version. | |
| 15 | + * | |
| 16 | + * Logtivity is distributed in the hope that it will be useful, | |
| 17 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 18 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 19 | + * GNU General Public License for more details. | |
| 20 | + * | |
| 21 | + * You should have received a copy of the GNU General Public License | |
| 22 | + * along with Logtivity. If not, see <https://www.gnu.org/licenses/>. | |
| 23 | + */ | |
| 24 | + | |
| 25 | +/** | |
| 26 | + * @var string $fileName | |
| 27 | + * @var ?string $message | |
| 28 | + * @var object[] $logs | |
| 29 | + * @var object $meta | |
| 30 | + * @var string $hasNextPage | |
| 31 | + */ | |
| 32 | + | |
| 33 | +?> | |
| 1 | 34 | <table class="form-table logtivity-table"> |
| 2 | - <thead> | |
| 3 | - <tr> | |
| 4 | - <th>Action</th> | |
| 5 | - <th>Context</th> | |
| 6 | - <th>User</th> | |
| 7 | - <th colspan="2">Date</th> | |
| 8 | - </tr> | |
| 9 | - </thead> | |
| 10 | - <tbody> | |
| 11 | - | |
| 12 | - <?php if (count($logs)): ?> | |
| 13 | - <?php foreach ($logs as $key => $log): ?> | |
| 35 | + <caption class="screen-reader-text"><?php esc_html_e('Activity logs', 'logtivity'); ?></caption> | |
| 36 | + <thead> | |
| 37 | + <tr> | |
| 38 | + <th scope="col">Action</th> | |
| 39 | + <th scope="col">Context</th> | |
| 40 | + <th scope="col">User</th> | |
| 41 | + <th scope="col">Date</th> | |
| 42 | + <th scope="col">Actions</th> | |
| 43 | + </tr> | |
| 44 | + </thead> | |
| 45 | + <tbody> | |
| 14 | 46 | |
| 15 | - <tr> | |
| 16 | - <td><?php echo sanitize_text_field($log->action) ?></td> | |
| 17 | - <td><?php echo sanitize_text_field($log->context) ?></td> | |
| 18 | - <td> | |
| 19 | - <div style="margin-bottom: 5px;"><?php echo sanitize_text_field($log->action_username ?? $log->action_user_id) ?></div> | |
| 20 | - <?php echo sanitize_text_field($log->ip_address) ?> | |
| 21 | - </td> | |
| 22 | - <td> | |
| 23 | - <?php echo sanitize_text_field(date('M d Y', strtotime($log->occurred_at))) ?> - <?php echo sanitize_text_field(date('H:i:s', strtotime($log->occurred_at))); ?> | |
| 24 | - </td> | |
| 25 | - <td> | |
| 26 | - <button class="button js-logtivity-view-log">View</button> | |
| 27 | - <div style="display: none;" class="js-modal-content"> | |
| 28 | - <?php echo logtivity_view('_log-show', [ | |
| 29 | - 'log' => $log | |
| 30 | - ]) ?> | |
| 31 | - </div> | |
| 32 | - </td> | |
| 33 | - </tr> | |
| 47 | + <?php if (count($logs)) : ?> | |
| 48 | + <?php foreach ($logs as $key => $log) : ?> | |
| 34 | 49 | |
| 35 | - <?php endforeach ?> | |
| 36 | - <?php else: ?> | |
| 37 | - <?php if (isset($message)): ?> | |
| 38 | - <tr> | |
| 39 | - <td colspan="6"><?php echo sanitize_text_field($message) ?></td> | |
| 40 | - </tr> | |
| 41 | - <?php else: ?> | |
| 42 | - <tr> | |
| 43 | - <td colspan="6">No results found.</td> | |
| 44 | - </tr> | |
| 45 | - <?php endif ?> | |
| 46 | - <?php endif ?> | |
| 50 | + <tr> | |
| 51 | + <td><?php echo sanitize_text_field($log->action) ?></td> | |
| 52 | + <td><?php echo sanitize_text_field($log->context) ?></td> | |
| 53 | + <td class="break-long"> | |
| 54 | + <div style="margin-bottom: 5px;"><?php echo sanitize_text_field($log->action_username ?? $log->action_user_id) ?></div> | |
| 55 | + <?php echo sanitize_text_field($log->ip_address) ?> | |
| 56 | + </td> | |
| 57 | + <td> | |
| 58 | + <small> | |
| 59 | + <?php echo logtivity_datetime($log->occurred_at); ?> | |
| 60 | + </small> | |
| 61 | + </td> | |
| 62 | + <td class="text-center"> | |
| 63 | + <button type="button" class="button js-logtivity-view-log" aria-haspopup="dialog" aria-controls="logtivity-log-modal" aria-label="<?php esc_attr_e('View log details', 'logtivity'); ?>">View</button> | |
| 64 | + <div style="display: none;" class="js-modal-content"> | |
| 65 | + <?php echo logtivity_view('_log-show', ['log' => $log,]) ?> | |
| 66 | + </div> | |
| 67 | + </td> | |
| 68 | + </tr> | |
| 47 | 69 | |
| 48 | - </tbody> | |
| 70 | + <?php endforeach ?> | |
| 71 | + <?php elseif (isset($message)) : ?> | |
| 72 | + <tr> | |
| 73 | + <td colspan="5"><?php echo sanitize_text_field($message) ?></td> | |
| 74 | + </tr> | |
| 75 | + <?php else : ?> | |
| 76 | + <tr> | |
| 77 | + <td colspan="5">No results found.</td> | |
| 78 | + </tr> | |
| 79 | + <?php endif ?> | |
| 80 | + </tbody> | |
| 49 | 81 | </table> |
| 50 | 82 | |
| 51 | -<?php if ($meta->current_page): ?> | |
| 52 | - | |
| 53 | - <div data-current-page="<?php echo $meta->current_page ?>" data-last-page="<?php echo $meta->last_page ?>" style="text-align: center; padding: 20px"> | |
| 54 | - | |
| 55 | - <button <?php echo ( $meta->current_page == 1 ? 'disabled' : ''); ?> class="js-logtivity-pagination button-primary" data-page="<?php echo sanitize_text_field($meta->current_page - 1) ?>">Previous</button> | |
| 56 | - | |
| 57 | - <button <?php echo ( ! $hasNextPage ? 'disabled' : ''); ?> class="js-logtivity-pagination button-primary" data-page="<?php echo sanitize_text_field($meta->current_page + 1) ?>">Next</button> | |
| 58 | - | |
| 59 | - </div> | |
| 83 | +<?php if ($meta->current_page ?? null) : ?> | |
| 84 | + <nav class="nav-pages-buttons" data-current-page="<?php echo esc_attr($meta->current_page) ?>" aria-label="<?php esc_attr_e('Log pages', 'logtivity'); ?>"> | |
| 85 | + <button type="button" <?php echo $meta->current_page == 1 ? 'disabled' : ''; ?> | |
| 86 | + class="js-logtivity-pagination button-primary nav-pages-prev" | |
| 87 | + aria-label="<?php esc_attr_e('Previous log page', 'logtivity'); ?>" | |
| 88 | + data-page="<?php echo esc_attr($meta->current_page - 1) ?>"> | |
| 89 | + « Previous | |
| 90 | + </button> | |
| 91 | + <button type="button" <?php echo $hasNextPage ? '' : 'disabled'; ?> | |
| 92 | + class="js-logtivity-pagination button-primary nav-pages-next" | |
| 93 | + aria-label="<?php esc_attr_e('Next log page', 'logtivity'); ?>" | |
| 94 | + data-page="<?php echo esc_attr($meta->current_page + 1) ?>">Next » | |
| 95 | + </button> | |
| 96 | + </nav> | |
| 60 | 97 | <?php endif ?> |
| 61 | 98 | |
| 62 | -<div class="logtivity-modal"> | |
| 63 | - <div class="logtivity-modal-dialog"> | |
| 64 | - <div class="logtivity-modal-content"> | |
| 65 | - <!-- Populated with JS --> | |
| 66 | - </div> | |
| 67 | - </div> | |
| 68 | -</div> | |
| 99 | +<div id="logtivity-log-modal" class="logtivity-modal" role="dialog" aria-modal="true" aria-hidden="true" aria-labelledby="logtivity-log-modal-title"> | |
| 100 | + <div class="logtivity-modal-dialog" tabindex="-1"> | |
| 101 | + <div class="logtivity-modal-content"> | |
| 102 | + <!-- Populated with JS --> | |
| 103 | + </div> | |
| 104 | + </div> | |
| 105 | +</div> | |