| 1 |
<?php |
| 2 |
|
| 3 |
use SyncBasalam\Logger\Logger; |
| 4 |
|
| 5 |
defined('ABSPATH') || exit; |
| 6 |
|
| 7 |
$logs = Logger::getLogs(); |
| 8 |
|
| 9 |
if (isset($logs['error'])) { |
| 10 |
echo '<div class="notice notice-error"><p class="basalam-p">' . esc_html($logs['error']) . '</p></div>'; |
| 11 |
|
| 12 |
return; |
| 13 |
} |
| 14 |
|
| 15 |
$logs_by_level = $logs['logs_by_level']; |
| 16 |
$current_tab = $logs['current_tab']; |
| 17 |
$current_page = $logs['current_page']; |
| 18 |
$per_page = $logs['per_page']; |
| 19 |
|
| 20 |
$tabs = [ |
| 21 |
'info' => 'اطلاعات', |
| 22 |
'warning' => 'هشدارها', |
| 23 |
'error' => 'خطاها', |
| 24 |
'debug' => 'دیباگ', |
| 25 |
'alert' => 'توجه', |
| 26 |
]; |
| 27 |
|
| 28 |
$total_logs = 0; |
| 29 |
foreach ($logs_by_level as $level_logs) { |
| 30 |
$total_logs += count($level_logs); |
| 31 |
} |
| 32 |
?> |
| 33 |
<div class="basalam-container basalam-p"> |
| 34 |
<!-- Header with Title and Clear Button --> |
| 35 |
<div class="log-basalam-header-section"> |
| 36 |
<div class="log-basalam-header-content"> |
| 37 |
<div class="log-basalam-header-left"> |
| 38 |
<h2 class="log-basalam-heading basalam-h">لاگهای پلاگین ووسلا� |
| 39 |
</h2> |
| 40 |
</div> |
| 41 |
<div class="log-basalam-header-actions"> |
| 42 |
<button id="basalam-clear-logs-btn" class="log-basalam-clear-logs-button" data-nonce="<?php echo esc_attr(wp_create_nonce('basalam_clear_logs_nonce')); ?>"> |
| 43 |
<img src="<?php echo esc_url(syncBasalamPlugin()->assetsUrl() . '/icons/trash.svg'); ?>" alt="حذف" class="log-basalam-btn-icon"> |
| 44 |
<span>حذف ه� |
| 45 |
ه لاگها</span> |
| 46 |
</button> |
| 47 |
</div> |
| 48 |
</div> |
| 49 |
</div> |
| 50 |
|
| 51 |
<!-- Tabs Section --> |
| 52 |
<div class="log-basalam-tabs-modern"> |
| 53 |
<?php foreach ($tabs as $tab => $label): ?> |
| 54 |
<a href="<?php echo esc_url(add_query_arg([ |
| 55 |
'page' => 'sync_basalam_logs', |
| 56 |
'tab' => $tab, |
| 57 |
'paged' => 1, |
| 58 |
], admin_url('admin.php'))); ?>" |
| 59 |
class="log-basalam-tab-button-modern <?php echo ($tab === $current_tab) ? 'log-basalam-active' : ''; ?>"> |
| 60 |
<span class="log-basalam-tab-icon log-basalam-tab-icon-<?php echo esc_attr($tab); ?>"></span> |
| 61 |
<span class="log-basalam-tab-label"><?php echo esc_html($label); ?></span> |
| 62 |
<span class="log-basalam-tab-count-modern"><?php echo esc_html(count($logs_by_level[$tab])); ?></span> |
| 63 |
</a> |
| 64 |
<?php endforeach; ?> |
| 65 |
</div> |
| 66 |
|
| 67 |
<?php foreach ($tabs as $tab => $label): ?> |
| 68 |
<div id="basalam-<?php echo esc_attr($tab); ?>" class="log-basalam-tab-content <?php echo ($tab === $current_tab) ? 'log-basalam-active' : ''; ?>"> |
| 69 |
<?php |
| 70 |
$logs = $logs_by_level[$tab]; |
| 71 |
$total_logs = count($logs); |
| 72 |
$total_pages = ceil($total_logs / $per_page); |
| 73 |
$offset = ($current_page - 1) * $per_page; |
| 74 |
$current_logs = array_slice($logs, $offset, $per_page); |
| 75 |
if (empty($current_logs)): ?> |
| 76 |
<div class="log-basalam-empty-state"> |
| 77 |
<div class="log-basalam-empty-icon">📋</div> |
| 78 |
<h3>هیچ لاگی در این بخش وجود ندارد</h3> |
| 79 |
<p>لاگهای جدید در اینجا ن� |
| 80 |
ایش داده خواهند شد</p> |
| 81 |
</div> |
| 82 |
<?php else: ?> |
| 83 |
<div class="log-basalam-log-count-modern">ن� |
| 84 |
ایش <?php echo esc_html(($offset + 1) . '-' . min($offset + $per_page, $total_logs) . ' از ' . $total_logs); ?> لاگ</div> |
| 85 |
<ul class="log-basalam-log-list-modern"> |
| 86 |
<?php foreach ($current_logs as $log): ?> |
| 87 |
<?php |
| 88 |
// Extract product_id from context if available (supports both 'product_id' and legacy 'شناسه_� |
| 89 |
حصول') |
| 90 |
$product_id = null; |
| 91 |
$edit_url = null; |
| 92 |
$view_url = null; |
| 93 |
|
| 94 |
if (!empty($log['context'])) { |
| 95 |
$context_data = json_decode(json_encode($log['context']), true); |
| 96 |
|
| 97 |
// Check for product_id (new format) or شناسه_� |
| 98 |
حصول (old format) |
| 99 |
if (!empty($context_data['product_id'])) { |
| 100 |
$product_id = intval($context_data['product_id']); |
| 101 |
} elseif (!empty($context_data['شناسه_� |
| 102 |
حصول'])) { |
| 103 |
$product_id = intval($context_data['شناسه_� |
| 104 |
حصول']); |
| 105 |
} |
| 106 |
|
| 107 |
// Generate URLs if product_id exists |
| 108 |
if ($product_id) { |
| 109 |
$edit_url = esc_url(admin_url("post.php?post=$product_id&action=edit")); |
| 110 |
$view_url = esc_url(get_permalink($product_id)); |
| 111 |
} |
| 112 |
} |
| 113 |
?> |
| 114 |
<li class="log-basalam-log-item-modern log-basalam-<?php echo esc_attr($tab); ?>"> |
| 115 |
<div class="log-basalam-log-header-modern"> |
| 116 |
<div class="log-basalam-log-meta"> |
| 117 |
<span class="log-basalam-log-date-modern"><?php echo esc_html($log['date']); ?></span> |
| 118 |
<span class="log-basalam-log-level-badge log-basalam-level-<?php echo esc_attr(strtolower($log['level'])); ?>"><?php echo esc_html($log['level']); ?></span> |
| 119 |
</div> |
| 120 |
<?php if (!empty($log['context'])): ?> |
| 121 |
<div class="log-basalam-context-toggle-modern" data-toggle="context">جزئیات</div> |
| 122 |
<?php endif; ?> |
| 123 |
</div> |
| 124 |
<div class="log-basalam-log-message-modern"> |
| 125 |
<?php echo esc_html($log['message']); ?> |
| 126 |
</div> |
| 127 |
<?php if (!empty($log['context'])): ?> |
| 128 |
<div class="log-basalam-log-context-modern"> |
| 129 |
<div class="log-basalam-context-content"> |
| 130 |
<pre class="log-basalam-context-json"><?php echo esc_html(json_encode($context_data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); ?></pre> |
| 131 |
<?php if (!empty($edit_url) && !empty($view_url)): ?> |
| 132 |
<div class="log-basalam-product-actions-modern"> |
| 133 |
<a href="<?php echo esc_url($edit_url); ?>" target="_blank" class="log-basalam-btn-modern log-basalam-edit-btn basalam-a" title="ویرایش � |
| 134 |
حصول"> |
| 135 |
<img src="<?php echo esc_url(syncBasalamPlugin()->assetsUrl() . '/icons/update.svg'); ?>" alt="ویرایش"> |
| 136 |
ویرایش � |
| 137 |
حصول |
| 138 |
</a> |
| 139 |
<a href="<?php echo esc_url($view_url); ?>" target="_blank" class="log-basalam-btn-modern log-basalam-view-btn basalam-a" title="� |
| 140 |
شاهده � |
| 141 |
حصول"> |
| 142 |
<img src="<?php echo esc_url(syncBasalamPlugin()->assetsUrl() . '/icons/info.svg'); ?>" alt="� |
| 143 |
شاهده"> |
| 144 |
� |
| 145 |
شاهده � |
| 146 |
حصول |
| 147 |
</a> |
| 148 |
</div> |
| 149 |
<?php endif; ?> |
| 150 |
</div> |
| 151 |
</div> |
| 152 |
<?php endif; ?> |
| 153 |
</li> |
| 154 |
<?php endforeach; ?> |
| 155 |
</ul> |
| 156 |
|
| 157 |
<?php if ($total_pages > 1): ?> |
| 158 |
<div class="log-basalam-pagination-modern"> |
| 159 |
<?php |
| 160 |
$current_url = add_query_arg([ |
| 161 |
'page' => 'sync_basalam_logs', |
| 162 |
'tab' => $tab, |
| 163 |
], admin_url('admin.php')); |
| 164 |
|
| 165 |
if ($current_page > 1): ?> |
| 166 |
<a href="<?php echo esc_url(add_query_arg('paged', 1, $current_url)); ?>" class="log-basalam-page-link-modern basalam-first">«</a> |
| 167 |
<?php endif; |
| 168 |
|
| 169 |
if ($current_page > 1): ?> |
| 170 |
<a href="<?php echo esc_url(add_query_arg('paged', $current_page - 1, $current_url)); ?>" class="log-basalam-page-link-modern basalam-prev">‹</a> |
| 171 |
<?php endif; |
| 172 |
|
| 173 |
$start_page = max(1, min($current_page - 2, $total_pages - 4)); |
| 174 |
$end_page = min($total_pages, max(5, $current_page + 2)); |
| 175 |
|
| 176 |
for ($i = $start_page; $i <= $end_page; $i++): ?> |
| 177 |
<a href="<?php echo esc_url(add_query_arg('paged', $i, $current_url)); ?>" |
| 178 |
class="log-basalam-page-link-modern <?php echo ($i === $current_page) ? 'log-basalam-active' : ''; ?>"> |
| 179 |
<?php echo esc_html($i); ?> |
| 180 |
</a> |
| 181 |
<?php endfor; |
| 182 |
|
| 183 |
if ($current_page < $total_pages): ?> |
| 184 |
<a href="<?php echo esc_url(add_query_arg('paged', $current_page + 1, $current_url)); ?>" class="log-basalam-page-link-modern basalam-next">›</a> |
| 185 |
<?php endif; |
| 186 |
|
| 187 |
if ($current_page < $total_pages): ?> |
| 188 |
<a href="<?php echo esc_url(add_query_arg('paged', $total_pages, $current_url)); ?>" class="log-basalam-page-link-modern basalam-last">»</a> |
| 189 |
<?php endif; ?> |
| 190 |
</div> |
| 191 |
<?php endif; ?> |
| 192 |
<?php endif; ?> |
| 193 |
</div> |
| 194 |
<?php endforeach; ?> |
| 195 |
</div> |
| 196 |
|
| 197 |
<!-- Clear Logs Confirmation Modal --> |
| 198 |
<div id="basalam-clear-logs-modal" class="log-basalam-modal"> |
| 199 |
<div class="log-basalam-modal-content"> |
| 200 |
<div class="log-basalam-modal-header"> |
| 201 |
<h3>حذف ه� |
| 202 |
ه لاگها</h3> |
| 203 |
<button class="log-basalam-modal-close">×</button> |
| 204 |
</div> |
| 205 |
<div class="log-basalam-modal-body"> |
| 206 |
<p>آیا � |
| 207 |
ط� |
| 208 |
ئن هستید که � |
| 209 |
یخواهید ه� |
| 210 |
ه لاگهای پلاگین ووسلا� |
| 211 |
را حذف کنید؟</p> |
| 212 |
<p class="log-basalam-warning-text"> این ع� |
| 213 |
لیات غیرقابل بازگشت است!</p> |
| 214 |
</div> |
| 215 |
<div class="log-basalam-modal-footer"> |
| 216 |
<button class="log-basalam-btn-modern log-basalam-btn-secondary" id="basalam-cancel-clear">انصراف</button> |
| 217 |
<button class="log-basalam-btn-modern log-basalam-btn-danger" id="basalam-confirm-clear">حذف ه� |
| 218 |
ه لاگها</button> |
| 219 |
</div> |
| 220 |
</div> |
| 221 |
</div> |