| 1 |
<?php |
| 2 |
|
| 3 |
namespace SyncBasalam\Utilities; |
| 4 |
|
| 5 |
defined('ABSPATH') || exit; |
| 6 |
|
| 7 |
class TicketExtraInfoFormatter |
| 8 |
{ |
| 9 |
public static function appendFromRequest(string $content, array $request): string |
| 10 |
{ |
| 11 |
$dashboardLines = self::collectDashboardLines($request); |
| 12 |
$hostPanelLines = self::collectHostPanelLines($request); |
| 13 |
|
| 14 |
if (empty($dashboardLines) && empty($hostPanelLines)) { |
| 15 |
return trim($content); |
| 16 |
} |
| 17 |
|
| 18 |
$sections = [trim($content)]; |
| 19 |
|
| 20 |
if (!empty($dashboardLines)) { |
| 21 |
$sections[] = "اطلاعات پیشخوان:\n" . implode("\n", $dashboardLines); |
| 22 |
} |
| 23 |
|
| 24 |
if (!empty($hostPanelLines)) { |
| 25 |
$sections[] = "کنترل پنل هاست:\n" . implode("\n", $hostPanelLines); |
| 26 |
} |
| 27 |
|
| 28 |
return trim(implode("\n\n", array_filter($sections))); |
| 29 |
} |
| 30 |
|
| 31 |
private static function collectDashboardLines(array $request): array |
| 32 |
{ |
| 33 |
$lines = []; |
| 34 |
|
| 35 |
$dashboardLoginUrl = self::sanitize($request['dashboard_login_url'] ?? ''); |
| 36 |
$dashboardUsername = self::sanitize($request['dashboard_username'] ?? ''); |
| 37 |
$dashboardPassword = self::sanitize($request['dashboard_password'] ?? ''); |
| 38 |
|
| 39 |
if ($dashboardLoginUrl !== '') $lines[] = 'آدرس لاگین پیشخوان: ' . $dashboardLoginUrl; |
| 40 |
if ($dashboardUsername !== '') $lines[] = 'نا� |
| 41 |
کاربری پیشخوان: ' . $dashboardUsername; |
| 42 |
if ($dashboardPassword !== '') $lines[] = 'ر� |
| 43 |
ز عبور پیشخوان: ' . $dashboardPassword; |
| 44 |
|
| 45 |
return $lines; |
| 46 |
} |
| 47 |
|
| 48 |
private static function collectHostPanelLines(array $request): array |
| 49 |
{ |
| 50 |
$lines = []; |
| 51 |
|
| 52 |
$hostPanelLoginUrl = self::sanitize($request['host_panel_login_url'] ?? ''); |
| 53 |
$hostPanelUsername = self::sanitize($request['host_panel_username'] ?? ''); |
| 54 |
$hostPanelPassword = self::sanitize($request['host_panel_password'] ?? ''); |
| 55 |
|
| 56 |
if ($hostPanelLoginUrl !== '') $lines[] = 'آدرس لاگین کنترل پنل هاست: ' . $hostPanelLoginUrl; |
| 57 |
if ($hostPanelUsername !== '') $lines[] = 'نا� |
| 58 |
کاربری کنترل پنل هاست: ' . $hostPanelUsername; |
| 59 |
if ($hostPanelPassword !== '') $lines[] = 'ر� |
| 60 |
ز عبور کنترل پنل هاست: ' . $hostPanelPassword; |
| 61 |
|
| 62 |
return $lines; |
| 63 |
} |
| 64 |
|
| 65 |
private static function sanitize($value): string |
| 66 |
{ |
| 67 |
return sanitize_text_field(wp_unslash((string) $value)); |
| 68 |
} |
| 69 |
} |
| 70 |
|