Upload via GUI (267 Dateien)
This commit is contained in:
@@ -66,14 +66,20 @@ function api_require_https(): void
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Liest die Anmeldung der Apps. Viele Hoster (Apache mit PHP-FPM/FastCGI, z. B. Plesk) reichen den Header "Authorization" nicht an PHP weiter.
|
||||
* Deshalb senden die Apps denselben Wert zusätzlich als "X-DeskHub-Authorization", der überall ankommt; hier gilt der erste vorhandene.
|
||||
*/
|
||||
function api_authorization_header(): string
|
||||
{
|
||||
$header = $_SERVER['HTTP_AUTHORIZATION'] ?? $_SERVER['REDIRECT_HTTP_AUTHORIZATION'] ?? '';
|
||||
if ($header === '' && function_exists('getallheaders')) {
|
||||
$headers = getallheaders();
|
||||
$header = $headers['Authorization'] ?? $headers['authorization'] ?? '';
|
||||
if (trim((string) $header) === '') $header = $_SERVER['HTTP_X_DESKHUB_AUTHORIZATION'] ?? '';
|
||||
if (trim((string) $header) === '' && function_exists('getallheaders')) {
|
||||
foreach (getallheaders() as $name => $value) {
|
||||
if (in_array(strtolower((string) $name), ['authorization', 'x-deskhub-authorization'], true) && trim((string) $value) !== '') { $header = $value; break; }
|
||||
}
|
||||
}
|
||||
return trim($header);
|
||||
return trim((string) $header);
|
||||
}
|
||||
|
||||
function api_bearer_token(): ?string
|
||||
@@ -204,11 +210,27 @@ function api_find_ticket(PDO $pdo, array $staff, string $number): array
|
||||
return $ticket;
|
||||
}
|
||||
|
||||
/** Adresse des ersten Bildes in einem HTML-Text (absolut, nur http/https); leer, wenn keines vorhanden ist. */
|
||||
function api_first_image_url(?string $html): string
|
||||
{
|
||||
if (!preg_match('/<img\b[^>]*\bsrc\s*=\s*(["\'])(.*?)\1/is', (string) $html, $m)) return '';
|
||||
$src = trim(html_entity_decode($m[2], ENT_QUOTES | ENT_HTML5, 'UTF-8'));
|
||||
if (str_starts_with($src, '//')) $src = 'https:' . $src;
|
||||
elseif (str_starts_with($src, '/')) $src = base_url() . $src;
|
||||
return preg_match('#^https?://#i', $src) ? $src : '';
|
||||
}
|
||||
|
||||
function api_plain_text(?string $html): string
|
||||
{
|
||||
$text = preg_replace('/<br\s*\/?>/i', "\n", (string) $html);
|
||||
$text = preg_replace('/<\/p\s*>/i', "\n\n", $text);
|
||||
return trim(html_entity_decode(strip_tags($text), ENT_QUOTES | ENT_HTML5, 'UTF-8'));
|
||||
// Weitere Blöcke (div, Listen, Tabellenzeilen, Überschriften …) enden ebenfalls mit einem Zeilenumbruch, Listenpunkte bekommen einen Punkt
|
||||
$text = preg_replace('/<li\b[^>]*>/i', '• ', $text);
|
||||
$text = preg_replace('/<\/(div|li|tr|h[1-6]|blockquote|pre|ul|ol|table)\s*>/i', "\n", $text);
|
||||
$text = html_entity_decode(strip_tags($text), ENT_QUOTES | ENT_HTML5, 'UTF-8');
|
||||
$text = preg_replace('/[ \t]+\n/', "\n", $text); // Leerzeichen am Zeilenende
|
||||
$text = preg_replace('/\n{3,}/', "\n\n", $text); // höchstens eine Leerzeile
|
||||
return trim($text);
|
||||
}
|
||||
|
||||
function api_ticket_summary(array $ticket): array
|
||||
@@ -247,7 +269,7 @@ function api_ticket_summary(array $ticket): array
|
||||
];
|
||||
}
|
||||
|
||||
function api_add_ticket_message(PDO $pdo, array $staff, array $ticket, string $type, string $rawMessage, ?string $setStatus): int
|
||||
function api_add_ticket_message(PDO $pdo, array $staff, array $ticket, string $type, string $rawMessage, ?string $setStatus, ?string $signatureChoice = null): int
|
||||
{
|
||||
$permission = $type === 'note' ? 'post_note' : 'reply_ticket';
|
||||
api_require_permission($staff, $permission, (int) $ticket['department_id']);
|
||||
@@ -331,12 +353,8 @@ function api_add_ticket_message(PDO $pdo, array $staff, array $ticket, string $t
|
||||
}
|
||||
|
||||
if (!$isNote) {
|
||||
$signature = trim((string) ($staff['signature'] ?? ''));
|
||||
if ($signature === '') {
|
||||
$signatureStmt = $pdo->prepare('SELECT signature FROM departments WHERE id = ?');
|
||||
$signatureStmt->execute([$ticket['department_id']]);
|
||||
$signature = (string) $signatureStmt->fetchColumn();
|
||||
}
|
||||
// Signatur: optional vom Aufrufer gewählt (own, dept, none), sonst eigene, ersatzweise die der Abteilung
|
||||
$signature = resolve_reply_signature($pdo, $staff, (int) $ticket['department_id'], $signatureChoice);
|
||||
$collabStmt = $pdo->prepare('SELECT email FROM ticket_collaborators WHERE ticket_id = ?');
|
||||
$collabStmt->execute([$ticket['id']]);
|
||||
notify_customer_new_reply($ticket, $message, $signature, $collabStmt->fetchAll(PDO::FETCH_COLUMN));
|
||||
|
||||
Reference in New Issue
Block a user