PluginProbe
ووسلام – همگام سازی ووکامرس و باسلام / 1.10.5
ووسلام – همگام سازی ووکامرس و باسلام v1.10.5
1.10.19 1.10.20 1.10.18 1.10.17 1.10.15 1.10.14 1.10.13 1.10.12 1.10.10 1.10.9 1.10.8 1.10.7 1.10.6 1.10.5 1.10.4 1.10.3 1.10.2 1.10.1 1.10.0 1.9.2 1.9.1 1.9.0 1.8.8 1.8.5 1.8.6 All 53 releases
sync-basalam / includes / Utilities / TicketExtraInfoFormatter.php

TicketExtraInfoFormatter.php in ووسلام – همگام سازی ووکامرس و باسلام 1.10.5, at includes/Utilities/TicketExtraInfoFormatter.php

86 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SyncBasalam\Utilities;
4
5 defined('ABSPATH') || exit;
6
7 class TicketExtraInfoFormatter
8 {
9 public static function sanitizeContent($value): string
10 {
11 $value = wp_check_invalid_utf8(wp_unslash((string) $value));
12
13 if (strpos($value, '<') !== false) {
14 $value = wp_pre_kses_less_than($value);
15 $value = wp_strip_all_tags($value, false);
16 $value = str_replace("<\n", "&lt;\n", $value);
17 }
18
19 $value = str_replace(["\r\n", "\r"], "\n", $value);
20 $value = preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/', '', $value);
21
22 return trim($value);
23 }
24
25 public static function appendFromRequest(string $content, array $request): string
26 {
27 $dashboardLines = self::collectDashboardLines($request);
28 $hostPanelLines = self::collectHostPanelLines($request);
29
30 if (empty($dashboardLines) && empty($hostPanelLines)) {
31 return trim($content);
32 }
33
34 $sections = [trim($content)];
35
36 if (!empty($dashboardLines)) {
37 $sections[] = "اطلاعات پیشخوان:\n" . implode("\n", $dashboardLines);
38 }
39
40 if (!empty($hostPanelLines)) {
41 $sections[] = "کنترل پنل هاست:\n" . implode("\n", $hostPanelLines);
42 }
43
44 return trim(implode("\n\n", array_filter($sections)));
45 }
46
47 private static function collectDashboardLines(array $request): array
48 {
49 $lines = [];
50
51 $dashboardLoginUrl = self::sanitize($request['dashboard_login_url'] ?? '');
52 $dashboardUsername = self::sanitize($request['dashboard_username'] ?? '');
53 $dashboardPassword = self::sanitize($request['dashboard_password'] ?? '');
54
55 if ($dashboardLoginUrl !== '') $lines[] = 'آدرس لاگین پیشخوان: ' . $dashboardLoginUrl;
56 if ($dashboardUsername !== '') $lines[] = 'نا�
57 کاربری پیشخوان: ' . $dashboardUsername;
58 if ($dashboardPassword !== '') $lines[] = 'ر�
59 ز عبور پیشخوان: ' . $dashboardPassword;
60
61 return $lines;
62 }
63
64 private static function collectHostPanelLines(array $request): array
65 {
66 $lines = [];
67
68 $hostPanelLoginUrl = self::sanitize($request['host_panel_login_url'] ?? '');
69 $hostPanelUsername = self::sanitize($request['host_panel_username'] ?? '');
70 $hostPanelPassword = self::sanitize($request['host_panel_password'] ?? '');
71
72 if ($hostPanelLoginUrl !== '') $lines[] = 'آدرس لاگین کنترل پنل هاست: ' . $hostPanelLoginUrl;
73 if ($hostPanelUsername !== '') $lines[] = 'نا�
74 کاربری کنترل پنل هاست: ' . $hostPanelUsername;
75 if ($hostPanelPassword !== '') $lines[] = 'ر�
76 ز عبور کنترل پنل هاست: ' . $hostPanelPassword;
77
78 return $lines;
79 }
80
81 private static function sanitize($value): string
82 {
83 return preg_replace('/\s+/', ' ', self::sanitizeContent($value));
84 }
85 }
86