File: //proc/thread-self/root/tmp/creator-studio-account-switcher.patch
*** Begin Patch
*** Update File: /home/kiwerkzeuge.de/public_html/creator-studio/_lib/bootstrap.php
@@
function cs_find_account(string $openId): ?array
{
$store = cs_load_account_store();
$account = $store['accounts'][$openId] ?? null;
return is_array($account) ? $account : null;
}
+
+function cs_account_public_label(array $account): string
+{
+ $profile = is_array($account['profile'] ?? null) ? $account['profile'] : [];
+ $username = trim((string) ($profile['username'] ?? ''));
+ if ($username !== '') {
+ return '@' . ltrim($username, '@');
+ }
+
+ foreach (['display_name', 'nickname'] as $field) {
+ $value = trim((string) ($profile[$field] ?? ''));
+ if ($value !== '') {
+ return $value;
+ }
+ }
+
+ $creatorInfo = is_array($account['creator_info'] ?? null) ? $account['creator_info'] : [];
+ $creatorUsername = trim((string) ($creatorInfo['creator_username'] ?? $creatorInfo['username'] ?? ''));
+ if ($creatorUsername !== '') {
+ return '@' . ltrim($creatorUsername, '@');
+ }
+
+ $creatorDisplay = trim((string) ($creatorInfo['display_name'] ?? $creatorInfo['nickname'] ?? ''));
+ return $creatorDisplay !== '' ? $creatorDisplay : 'Connected TikTok account';
+}
+
+function cs_session_account_ref(string $openId): string
+{
+ $openId = trim($openId);
+ if ($openId === '') {
+ return '';
+ }
+ $sessionSalt = (session_id() !== '' ? session_id() : 'creator-studio') . ':' . cs_get_csrf_token();
+ return substr(hash_hmac('sha256', $openId, $sessionSalt), 0, 24);
+}
+
+function cs_resolve_session_account_ref(string $accountRef): ?string
+{
+ $accountRef = trim($accountRef);
+ if ($accountRef === '') {
+ return null;
+ }
+ foreach (cs_get_session_open_ids() as $openId) {
+ $expected = cs_session_account_ref($openId);
+ if ($expected !== '' && hash_equals($expected, $accountRef)) {
+ return $openId;
+ }
+ }
+ return null;
+}
+
+function cs_session_account_options(): array
+{
+ $ids = cs_get_session_open_ids();
+ $currentOpenId = cs_get_current_open_id();
+ if ($currentOpenId !== null && !in_array($currentOpenId, $ids, true)) {
+ array_unshift($ids, $currentOpenId);
+ }
+
+ $options = [];
+ foreach (array_values(array_unique($ids)) as $openId) {
+ $account = cs_find_account($openId);
+ if ($account === null) {
+ continue;
+ }
+ $creatorInfoReady = is_array($account['creator_info'] ?? null) && ($account['creator_info'] ?? []) !== [];
+ $options[] = [
+ 'ref' => cs_session_account_ref($openId),
+ 'label' => cs_account_public_label($account),
+ 'scope_count' => count(cs_get_scope_list($account)),
+ 'creator_info_ready' => $creatorInfoReady,
+ 'operation_count' => count(array_values(array_filter($account['operations'] ?? [], 'is_array'))),
+ 'agency_linked' => trim((string) ($account['agency_workspace_id'] ?? '')) !== '',
+ 'last_sync_at' => (string) ($account['last_sync_at'] ?? ''),
+ 'is_current' => $currentOpenId !== null && hash_equals($currentOpenId, $openId),
+ ];
+ }
+
+ return $options;
+}
function cs_creator_studio_account_activity_metrics(array $accounts, ?int $now = null): array
{
*** Update File: /home/kiwerkzeuge.de/public_html/creator-studio/_lib/redesign.php
@@
function cs_r_handle_post(string $lang, string $page): void
{
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
return;
}
$action = (string) ($_POST['action'] ?? '');
+ if ($action === 'switch-tiktok-account') {
+ try {
+ if (!cs_verify_csrf($_POST['csrf'] ?? null)) {
+ throw new RuntimeException(cs_r_lang($lang) === 'en' ? 'The form token was invalid. Reload and try again.' : 'Das Formular-Token war ungültig. Bitte neu laden.');
+ }
+ if (trim((string) ($_POST['website'] ?? '')) !== '') {
+ cs_set_flash('success', 'OK', cs_r_lang($lang) === 'en' ? 'Account unchanged.' : 'Konto unverändert.');
+ header('Location: ' . cs_r_url($lang, $page) . '#account', true, 303);
+ exit;
+ }
+ $openId = cs_resolve_session_account_ref((string) ($_POST['account_ref'] ?? ''));
+ if ($openId === null) {
+ throw new RuntimeException(cs_r_lang($lang) === 'en' ? 'This account is not available in the current browser session. Connect it again before switching.' : 'Dieses Konto ist in der aktuellen Browser-Session nicht verfügbar. Verbinde es erneut, bevor du wechselst.');
+ }
+ $account = cs_find_account($openId);
+ if ($account === null) {
+ throw new RuntimeException(cs_r_lang($lang) === 'en' ? 'The selected TikTok account is no longer stored.' : 'Das gewählte TikTok-Konto ist nicht mehr gespeichert.');
+ }
+ cs_set_current_open_id($openId);
+ cs_set_flash('success', cs_r_lang($lang) === 'en' ? 'TikTok account selected' : 'TikTok-Konto gewählt', cs_r_lang($lang) === 'en' ? 'New reviews and publish actions now use ' . cs_account_public_label($account) . '.' : 'Neue Reviews und Publishing-Aktionen nutzen jetzt ' . cs_account_public_label($account) . '.');
+ } catch (Throwable $error) {
+ cs_set_flash('error', cs_r_lang($lang) === 'en' ? 'Account switch failed' : 'Kontowechsel fehlgeschlagen', $error->getMessage());
+ }
+ header('Location: ' . cs_r_url($lang, $page) . '#account', true, 303);
+ exit;
+ }
if ($action === 'photo-carousel-brief') {
try {
if (!cs_verify_csrf($_POST['csrf'] ?? null)) {
throw new RuntimeException(cs_r_lang($lang) === 'en' ? 'The form token was invalid. Reload and try again.' : 'Das Formular-Token war ungültig. Bitte neu laden.');
@@
<?php if ($page === 'app'): ?><script defer src="/creator-studio/assets/creator-studio.js?v=20260312-3"></script><?php endif; ?>
@@
function cs_r_product_mock(array $copy): void
{
@@
}
+
+function cs_r_account_switcher(string $lang, array $copy, string $variant = 'wide'): void
+{
+ $isEn = $lang === 'en';
+ $options = cs_session_account_options();
+ $current = null;
+ foreach ($options as $option) {
+ if (!empty($option['is_current'])) {
+ $current = $option;
+ break;
+ }
+ }
+ if ($current === null && $options !== []) {
+ $current = $options[0];
+ }
+ $count = count($options);
+ $title = $current !== null ? (string) ($current['label'] ?? '') : ($isEn ? 'No TikTok connected' : 'Kein TikTok verbunden');
+ $caption = $count > 1
+ ? ($isEn ? 'Switch the active account before reviewing or sending content to TikTok.' : 'Wechsle das aktive Konto, bevor du Content prüfst oder an TikTok sendest.')
+ : ($isEn ? 'Connect another TikTok account here when you need a second creator or client slot.' : 'Verbinde hier ein weiteres TikTok-Konto, wenn du einen zweiten Creator- oder Kundenslot brauchst.');
+ $classes = 'cs-account-mini cs-account-panel' . ($variant === 'side' ? ' compact' : '');
+ ?>
+ <div class="<?= cs_h($classes) ?>" id="account">
+ <div class="cs-account-head">
+ <span class="cs-status-pill <?= $count > 0 ? 'ready' : 'action_needed' ?>"><?= cs_h($count > 0 ? cs_r_status_label('ready', $lang) : cs_r_status_label('action_needed', $lang)) ?></span>
+ <strong><?= cs_h($title) ?></strong>
+ <p class="cs-form-help"><?= cs_h($caption) ?></p>
+ </div>
+ <?php if ($count > 1): ?>
+ <form class="cs-account-switcher" method="post">
+ <input type="hidden" name="csrf" value="<?= cs_h(cs_get_csrf_token()) ?>" />
+ <input type="hidden" name="action" value="switch-tiktok-account" />
+ <input type="text" name="website" value="" tabindex="-1" autocomplete="off" class="cs-hp" aria-hidden="true" />
+ <label class="cs-field"><span><?= cs_h($isEn ? 'Active TikTok account' : 'Aktives TikTok-Konto') ?></span><select name="account_ref" required>
+ <?php foreach ($options as $option): ?>
+ <?php
+ $meta = [];
+ $meta[] = (int) ($option['scope_count'] ?? 0) . ' scopes';
+ $meta[] = !empty($option['creator_info_ready']) ? ($isEn ? 'Creator Info ready' : 'Creator Info bereit') : ($isEn ? 'Creator Info open' : 'Creator Info offen');
+ if ((int) ($option['operation_count'] ?? 0) > 0) {
+ $meta[] = (int) $option['operation_count'] . ($isEn ? ' publish ops' : ' Publish-Läufe');
+ }
+ if (!empty($option['agency_linked'])) {
+ $meta[] = $isEn ? 'agency slot' : 'Agentur-Slot';
+ }
+ ?>
+ <option value="<?= cs_h((string) ($option['ref'] ?? '')) ?>" <?= !empty($option['is_current']) ? 'selected' : '' ?>><?= cs_h((string) ($option['label'] ?? 'TikTok')) ?> · <?= cs_h(implode(' · ', $meta)) ?></option>
+ <?php endforeach; ?>
+ </select></label>
+ <button class="cs-button secondary" type="submit"><?= cs_h($isEn ? 'Switch' : 'Wechseln') ?></button>
+ </form>
+ <?php elseif ($count === 1 && $current !== null): ?>
+ <div class="cs-account-state">
+ <span><?= cs_h((int) ($current['scope_count'] ?? 0) . ' scopes') ?></span>
+ <span><?= cs_h(!empty($current['creator_info_ready']) ? ($isEn ? 'Creator Info ready' : 'Creator Info bereit') : ($isEn ? 'Creator Info open' : 'Creator Info offen')) ?></span>
+ <span><?= cs_h((int) ($current['operation_count'] ?? 0) . ($isEn ? ' publish ops' : ' Publish-Läufe')) ?></span>
+ </div>
+ <?php endif; ?>
+ <div class="cs-actions compact"><a class="cs-button secondary" href="/creator-studio/auth/tiktok/start.php"><?= cs_h($count > 0 ? ($isEn ? 'Connect another TikTok' : 'Weiteres TikTok verbinden') : $copy['cta_tiktok']) ?></a></div>
+ </div>
+ <?php
+}
function cs_r_home(string $lang, array $copy): void
{
@@
- <link rel="stylesheet" href="/creator-studio/assets/creator-redesign.css?v=20260614-16" />
+ <link rel="stylesheet" href="/creator-studio/assets/creator-redesign.css?v=20260614-17" />
*** End Patch