' . esc_html__('الإعدادات', 'bunstream') . ''); return $links; } public static function register() { register_setting('bunstream', BunStream_Options::OPTION, array( 'type' => 'array', 'sanitize_callback' => array(__CLASS__, 'sanitize'), 'default' => array(), )); } /** Blank key / secret fields keep what is stored; the "remove" boxes clear them. */ public static function sanitize($input) { $old = BunStream_Options::all(); $input = is_array($input) ? $input : array(); $out = $old; // https only: the key travels in a header on every call. $base = isset($input['api_base']) ? esc_url_raw(trim((string) $input['api_base']), array('https')) : ''; $out['api_base'] = $base !== '' ? untrailingslashit($base) : BUNSTREAM_DEFAULT_BASE; $key = isset($input['api_key']) ? trim(sanitize_text_field((string) $input['api_key'])) : ''; if (!empty($input['remove_key'])) { $out['api_key'] = ''; } elseif ($key !== '') { if (strpos($key, 'bsr_') !== 0) { add_settings_error('bunstream', 'bunstream_key', __('المفتاح لازم يبدأ بـ bsr_ — اعمل «مفتاح WordPress» من صفحة «ربط المنصة» في BunStream (مش مفتاح تطبيق الرفع).', 'bunstream')); } else { $out['api_key'] = $key; } } $source = isset($input['id_source']) ? (string) $input['id_source'] : 'user_id'; $out['id_source'] = in_array($source, BunStream_Options::ID_SOURCES, true) ? $source : 'user_id'; $secret = isset($input['signing_secret']) ? trim(sanitize_text_field((string) $input['signing_secret'])) : ''; if (!empty($input['remove_secret'])) { $out['signing_secret'] = ''; } elseif ($secret !== '') { $out['signing_secret'] = $secret; } if ($out['api_key'] !== $old['api_key'] || $out['api_base'] !== $old['api_base']) { BunStream_Api::flush_cache(); delete_option(BunStream_Options::ACCOUNT_OPTION); } return $out; } public static function test_connection() { if (!current_user_can('manage_options')) { wp_die(esc_html__('غير مسموح.', 'bunstream'), 403); } check_admin_referer('bunstream_test'); $account = BunStream_Api::refresh_account(true); $result = is_wp_error($account) ? array('ok' => false, 'message' => $account->get_error_message()) : array('ok' => true); set_transient('bunstream_test_' . get_current_user_id(), $result, 120); wp_safe_redirect(admin_url('options-general.php?page=' . self::PAGE . '&bunstream_tested=1')); exit; } /** Does the account's domain list let this site play? Mirrors BunStream's UserDomain::matches. */ public static function site_allowed(array $domains, $host) { if (!$domains) { return true; } $host = strtolower((string) $host); $bare = function ($h) { return strpos($h, 'www.') === 0 ? substr($h, 4) : $h; }; foreach ($domains as $allowed) { $allowed = strtolower((string) $allowed); $allowed_host = explode(':', $allowed); $allowed_host = $allowed_host[0]; if ($host === $allowed_host || $bare($host) === $bare($allowed_host)) { return true; } if (strpos($allowed_host, '*.') === 0) { $base = substr($allowed_host, 2); if ($host === $base || substr($host, -strlen('.' . $base)) === '.' . $base) { return true; } } } return false; } public static function page() { if (!current_user_can('manage_options')) { return; } $opts = BunStream_Options::all(); $account = BunStream_Options::account(); $host = wp_parse_url(home_url(), PHP_URL_HOST); $test = null; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- only says a result may be waiting; the result is this user's own transient. if (isset($_GET['bunstream_tested'])) { $test = get_transient('bunstream_test_' . get_current_user_id()); delete_transient('bunstream_test_' . get_current_user_id()); } $requires_signed = !empty($account['require_signed_student_id']); ?>
[bunstream id="VIDEO_UUID" max-width="800px"]