using System; using System.Text; using System.Text.Encodings.Web; namespace Everything2Everything.Core.Ads; /// /// Google AdMob / AdSense 실서비스 태그 및 리치 배너 HTML5 문서를 빌드하는 헬퍼 /// public static class AdHtmlBuilder { public static string BuildBannerHtml(AdMobConfig config, AdItem ad) { var isTest = config.UseTestAds; if (isTest) { var sbTest = new StringBuilder(); sbTest.AppendLine(""); sbTest.AppendLine(""); sbTest.AppendLine(""); sbTest.AppendLine(""); sbTest.AppendLine(""); sbTest.AppendLine("Google Official Test Ad"); sbTest.AppendLine(""); sbTest.AppendLine(""); sbTest.AppendLine(""); sbTest.AppendLine(""); sbTest.AppendLine(""); sbTest.AppendLine("
"); sbTest.AppendLine("
"); sbTest.AppendLine("
"); sbTest.AppendLine(" "); sbTest.AppendLine("
"); sbTest.AppendLine("
"); sbTest.AppendLine("
"); sbTest.AppendLine(""); sbTest.AppendLine(""); return sbTest.ToString(); } var pubId = config.PublisherId.Trim(); if (!pubId.StartsWith("pub-", StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(pubId)) { pubId = "pub-" + pubId; } var clientKey = string.IsNullOrEmpty(pubId) ? "ca-pub-3940256099942544" : "ca-" + pubId; var slot = "6300978111"; // Google 공식 샘플 슬롯 if (!string.IsNullOrEmpty(config.BannerAdUnitId)) { var slashIdx = config.BannerAdUnitId.LastIndexOf('/'); if (slashIdx >= 0 && slashIdx < config.BannerAdUnitId.Length - 1) { slot = config.BannerAdUnitId.Substring(slashIdx + 1); } else { slot = config.BannerAdUnitId; } } var title = HtmlEncoder.Default.Encode(ad.Title ?? (isTest ? "Nice job! Google AdMob 공식 테스트 광고" : "Google AdMob 공식 배너")); var desc = HtmlEncoder.Default.Encode(ad.Description ?? (isTest ? "[테스트 모드 활성] 단위: ca-app-pub-3940256099942544/6300978111" : "Everything2Everything 공식 후원 파트너십")); var targetUrl = ad.TargetUrl ?? (isTest ? "https://developers.google.com/admob/android/test-ads" : "https://admob.google.com"); var ctaText = HtmlEncoder.Default.Encode(ad.CtaText ?? (isTest ? "테스트 안내" : "자세히 보기")); var badge = HtmlEncoder.Default.Encode(ad.BadgeText ?? (isTest ? "TEST AD" : "Google AdMob")); var testAttr = isTest ? " data-ad-test=\"on\"" : ""; var sb = new StringBuilder(); sb.AppendLine(""); sb.AppendLine(""); sb.AppendLine(""); sb.AppendLine(""); sb.AppendLine(""); sb.AppendLine("Google AdMob Live Banner"); sb.AppendLine(""); sb.Append(""); sb.AppendLine(""); sb.AppendLine(""); sb.Append("
"); sb.AppendLine("
"); sb.AppendLine(" "); sb.AppendLine(" "); sb.AppendLine(" "); sb.AppendLine(" "); sb.AppendLine(" "); sb.AppendLine(" "); sb.AppendLine(" "); sb.Append("
"); sb.Append(" ").Append(badge).AppendLine(""); sb.AppendLine("
"); sb.AppendLine("
"); sb.Append("
").Append(title).AppendLine("
"); sb.Append("
").Append(desc).AppendLine("
"); sb.AppendLine("
"); sb.AppendLine("
"); sb.AppendLine("
"); sb.Append("
"); sb.Append(" ").Append(ctaText).AppendLine(""); sb.AppendLine(" "); sb.AppendLine(" "); sb.AppendLine(" "); sb.AppendLine("
"); sb.AppendLine("
"); sb.AppendLine(" AdChoices"); sb.AppendLine(" "); sb.AppendLine(" "); sb.AppendLine(" "); sb.AppendLine("
"); sb.AppendLine("
"); sb.AppendLine(" "); sb.AppendLine("
"); sb.Append(" "); sb.AppendLine("
"); sb.AppendLine("
"); sb.AppendLine(""); sb.AppendLine(""); sb.AppendLine(""); return sb.ToString(); } }