Exemplo n.º 1
0
 private void SetHyperlinkLabel(string value)
 {
     if (Label != null)
     {
         Label.Controls.Clear();
         Control label;
         if (IsNullOrWhiteSpace(value))
         {
             label = new LiteralControl(Description);
         }
         else
         {
             var tooltip = (HyperlinkToolTip ?? "Visit {link}").Replace("{link}",
                                                                        value);
             label = new HyperLink
             {
                 Text        = Description,
                 NavigateUrl = VotePage.NormalizeUrl(value),
                 Target      = "view",
                 ToolTip     = tooltip
             }.AddCssClasses("tiptip");
         }
         label.AddTo(Label);
     }
 }
Exemplo n.º 2
0
        private static string CreateImageAnchor(string href, string src,
                                                string title = "", string target = "")
        {
            if (string.IsNullOrWhiteSpace(href))
            {
                return(string.Empty);
            }
            if (string.IsNullOrWhiteSpace(src))
            {
                return(string.Empty);
            }
            href = VotePage.NormalizeUrl(href);
            src  = VotePage.NormalizeUrl(src);
            var a = new HtmlAnchor
            {
                HRef   = href,
                Title  = title,
                Target = target
            };

            new HtmlImage {
                Src = src
            }.AddTo(a);
            return(a.RenderToString());
        }
Exemplo n.º 3
0
 public static string LookupChannelId(string url, int retries = 0)
 {
     // There's gotta be a better way...
     // Accepts a "friendly" channel url like:
     //   [www.]youtube.com/c/{name}[?...]
     //   [www.]youtube.com/cuser/{name}[?...]
     //   [www.]youtube.com/{name}[?...]
     //Fetches the page and looks for either
     // 1. data-channel-external-id="{channelId"
     // 2. <link rel="canonical" href="https://www.youtube.com/channel/{channelId}">
     try
     {
         var page  = new WebClient().DownloadString(VotePage.NormalizeUrl(url));
         var match = ChannelIdRegex1.Match(page);
         if (match.Success)
         {
             return(match.Groups["id"].Captures[0].Value);
         }
         match = ChannelIdRegex2.Match(page);
         if (match.Success)
         {
             return(match.Groups["id"].Captures[0].Value);
         }
         return(null);
     }
     catch
     {
         if (retries <= 0)
         {
             return(null);
         }
     }
     return(LookupChannelId(url, retries - 1));
 }
Exemplo n.º 4
0
        //private static string RenderBannerAd(string adType, string stateCode, string electionKey,
        //  string officeKey, bool show)
        //{
        //  //if (UrlManager.IsLive /*&& adType != "H"*/) return Empty;
        //  var adTable = BannerAds.GetRenderInfoData(adType, stateCode, electionKey, officeKey);
        //  if (adTable.Count == 0) return Empty;
        //  var ad = adTable[0];
        //  if (!ad.AdEnabled && !show) return Empty;

        //  return $"<div class=\"banner-ad-outer\"><a href=\"{VotePage.NormalizeUrl(ad.AdUrl)}\"" +
        //    $" target=\"ad\"><img src=\"/banneradimage?{adType}.{stateCode}.{electionKey}.{officeKey}.{DateTime.UtcNow.Ticks}\"" +
        //    " alt=\"Ad Image\"/></a><p class=\"paid-advertisement-notice\">Paid Advertisement</p>" +
        //    "<hr /></div>";
        //}

        //public static string RenderBannerAd(string adType, string stateCode, string electionKey,
        //  string officeKey, bool show, int orgId, bool forAdmin = false)
        //{
        //  //if (UrlManager.IsLive /*&& adType != "H"*/) return Empty;
        //  // If orgID is non zero, the organzation ad will be shown. If the org has no ad, no ad will be shown.
        //  if (orgId == 0)
        //    return RenderBannerAd(adType, stateCode, electionKey, officeKey, show);

        //  var adTable = Organizations.GetAdData(orgId);
        //  if (adTable.Count == 0) return Empty;
        //  var ad = adTable[0];
        //  if (IsNullOrWhiteSpace(ad.AdImageName)) return Empty;
        //  var src = forAdmin
        //    ? GetAdjustedSiteUri("orgadimage", $"{orgId}.{DateTime.UtcNow.Ticks}")
        //    : $"/orgadimage?{orgId}.{DateTime.UtcNow.Ticks}";
        //  var onClick = IsNullOrWhiteSpace(ad.AdUrl)
        //    ? "onclick=\"return false;\""
        //    : Empty;

        //  return $"<div class=\"banner-ad-outer\"><a href=\"{VotePage.NormalizeUrl(ad.AdUrl)}\"" +
        //    $" {onClick} target=\"ad\"><img src=\"{src}\"" +
        //    " alt=\"Ad Image\"/></a><p class=\"paid-advertisement-notice\">Paid Advertisement</p>" +
        //    "<hr /></div>";
        //}

        public static string RenderBannerAd2(string adType, string stateCode, string electionKey,
                                             string officeKey, bool show)
        {
            var adTable = BannerAds.GetRenderInfo2Data(adType, stateCode, electionKey, officeKey);

            if (adTable.Count == 0)
            {
                return(Empty);
            }
            var ad = adTable[0];

            if (!ad.AdEnabled && !show)
            {
                return(Empty);
            }
            var descriptionLines = new List <string>();

            if (!IsNullOrWhiteSpace(ad.AdDescription1))
            {
                descriptionLines.Add($"<div class=\"ad3-description\"><p>{ad.AdDescription1}</p>");
                if (!IsNullOrWhiteSpace(ad.AdDescription2))
                {
                    descriptionLines.Add($"<p>{ad.AdDescription2}</p>");
                }
                if (!IsNullOrWhiteSpace(ad.AdDescriptionUrl))
                {
                    descriptionLines.Insert(0, $"<a href=\"{VotePage.NormalizeUrl(ad.AdDescriptionUrl)}\" target=\"_blank\">");
                    descriptionLines.Add("</a>");
                }
                descriptionLines.Add("</div>");
            }

            var thumbnailId       = ad.AdYouTubeUrl.GetYouTubeVideoId();
            var paidAdvertisement = ad.AdIsPaid
        ? "<p class=\"ad3-paid-advertisement-notice\">Paid Advertisement</p>"
        : Empty;
            var imgSource = IsNullOrWhiteSpace(ad.AdImageName)
        ? $"http://i.ytimg.com/vi/{thumbnailId}/hqdefault.jpg"
        : $"{GetAdjustedSiteUri("banneradimage", $"{ adType}.{ stateCode}.{ electionKey}.{ officeKey}.{ DateTime.UtcNow.Ticks}")}";

            return(ad.AdMediaType == "Y"
        ? "<div class=\"ad3-outer ad3-yt\"><div class=\"ad3-inner\"><div class=\"ad3-copy\">" +
                   $"{Join(Empty, descriptionLines)}</div>" +
                   $"<div class=\"ad3-right-wrapper\"><a class=\"ad3-video-wrapper-outer\" target=\"youtube\" href=\"{VotePage.NormalizeUrl(ad.AdYouTubeUrl)}\">" +
                   "<div class=\"ad3-video-container\"><div class=\"ad3-video-player\"><div>" +
                   //$"<img class=\"video-thumb\" src=\"http://i.ytimg.com/vi/{thumbnailId}/hqdefault.jpg\"/>" +
                   $"<img class=\"ad3-video-thumb\" src=\"{imgSource}\"/>" +
                   "<div class=\"video-play-button yt-play-button\"></div></div></div></div></a></div>" +
                   $"</div>{paidAdvertisement}</div>"

        : "<div class=\"ad3-outer ad3-img\"><div class=\"ad3-inner\"><div class=\"ad3-copy\">" +
                   $"{Join(Empty, descriptionLines)}</div>" +
                   $"<div class=\"ad3-right-wrapper\"><div class=\"ad3-image-wrapper\"><a class=\"ad3-image-link\" target=\"ext\" href=\"{VotePage.NormalizeUrl(ad.AdUrl)}\">" +
                   //$"<img class=\"ad-image\" src=\"{GetAdjustedSiteUri("banneradimage", $"{adType}.{stateCode}.{electionKey}.{officeKey}.{DateTime.UtcNow.Ticks}")}\" /></a></div></div>" +
                   $"<img class=\"ad3-image\" src=\"{imgSource}\" /></a></div></div>" +
                   $"</div>{paidAdvertisement}</div>");
        }
Exemplo n.º 5
0
        public static string RenderOneAd(string electionKey, string officeKey, string adType,
                                         string politicianKey, string politicianName, string videoUrl, string thumbnailId,
                                         string sponsor, string sponsorUrl, bool isCandidateSponsored)
        {
            string paidMessage;

            if (isCandidateSponsored)
            {
                var url = IsNullOrWhiteSpace(sponsorUrl)
          ? UrlManager.GetIntroPageUri(politicianKey).ToString()
          : VotePage.NormalizeUrl(sponsorUrl);
                paidMessage =
                    "Paid advertisement by<br/><a target=\"_blank\"" +
                    $" href=\"{url}\">candidate&rsquo;s campaign</a>";
            }
            else if (!IsNullOrWhiteSpace(sponsor))
            {
                paidMessage = IsNullOrWhiteSpace(sponsorUrl)
          ? $"Paid advertisement by<br/>{sponsor}"
          : $"Paid advertisement by<br/><a target=\"_blank\" href=\"{VotePage.NormalizeUrl(sponsorUrl)}\">" +
                              $"{sponsor}</a>";
            }
            else
            {
                paidMessage = "Paid advertisement";
            }

            var website = adType == "I"
        ? VotePage.NormalizeUrl(Politicians.GetPublicWebAddress(politicianKey))
        : Empty;

            return(adType == "Y"
        ? "<div class=\"ad-outer flex\"><div class=\"ad-inner\"><div class=\"ad-copy\">" +
                   $"<p class=\"ad-name\">{politicianName}</p>" +
                   $"<p class=\"paid-ad\">{paidMessage}</p></div><div class=\"right-wrapper\">" +
                   $"<img class=\"ad-profile\" src=\"/Image.aspx?Id={politicianKey}&Col=Headshot100\"/>" +
                   $"<a class=\"video-wrapper-outer\" target=\"youtube\" href=\"{VotePage.NormalizeUrl(videoUrl)}\">" +
                   "<div class=\"video-container\"><div class=\"video-player\"><div>" +
                   $"<img class=\"video-thumb\" src=\"http://i.ytimg.com/vi/{thumbnailId}/hqdefault.jpg\"/>" +
                   "<div class=\"video-play-button\"></div></div></div></div></a>" +
                   "<div style=\"clear:both\"></div></div></div></div>"
        : "<div class=\"ad-outer flex\"><div class=\"ad-inner\"><div class=\"ad-copy\">" +
                   $"<p class=\"ad-name\">{politicianName}</p>" +
                   $"<p class=\"paid-ad\">{paidMessage}</p></div><div class=\"right-wrapper\">" +
                   $"<img class=\"ad-profile\" src=\"/Image.aspx?Id={politicianKey}&Col=Headshot100\"/>" +
                   $"<div class=\"image-wrapper\"><a class=\"image-link\" target=\"ext\" href=\"{website}\">" +
                   $"<img class=\"ad-image\" src=\"/adimage?{electionKey}.{officeKey}.{politicianKey}\" /></a></div>" +
                   "</div></div></div></div>");
        }
Exemplo n.º 6
0
        private static void CreateOneMediumAnchor(Control ul, string webAddress,
                                                  SocialMedium medium, string politicianName, bool useLargeIcons = false)
        {
            var li = new HtmlLi().AddTo(ul);
            var a  =
                new HyperLink
            {
                NavigateUrl = VotePage.NormalizeUrl(webAddress),
                Target      = medium.Name.ToLowerInvariant(),
                ToolTip     = medium.GetTooltip(politicianName)
            }.AddTo(li);

            new Image {
                ImageUrl = useLargeIcons ? medium.LargeImageUrl : medium.ImageUrl
            }.AddTo(a);
        }
Exemplo n.º 7
0
        public static string CreateWebAnchor(string href, string anchorText = "",
                                             string title = "", string target = "")
        {
            if (string.IsNullOrWhiteSpace(href))
            {
                return(string.Empty);
            }
            if (string.IsNullOrWhiteSpace(anchorText))
            {
                anchorText = href;
            }
            href = VotePage.NormalizeUrl(href);
            var a = new HtmlAnchor
            {
                HRef      = href,
                InnerHtml = anchorText,
                Title     = title,
                Target    = target
            };

            return(a.RenderToString());
        }
Exemplo n.º 8
0
        public static string RenderBannerAd(string adType, string stateCode, string electionKey,
                                            string officeKey, bool show, int orgId, bool forAdmin = false)
        {
            if (UrlManager.IsLive && adType == "H" && orgId == 0)
            {
                return(Empty);                                            // disable home ads for now
            }
            // If orgID is non zero, the organzation ad will be shown. If the org has no ad, no ad will be shown.
            if (orgId == 0)
            {
                return(RenderBannerAd2(adType, stateCode, electionKey, officeKey, show));
            }

            var adTable = Organizations.GetAdData(orgId);

            if (adTable.Count == 0)
            {
                return(Empty);
            }
            var ad = adTable[0];

            if (IsNullOrWhiteSpace(ad.AdImageName))
            {
                return(Empty);
            }
            var src = forAdmin
        ? GetAdjustedSiteUri("orgadimage", $"{orgId}.{DateTime.UtcNow.Ticks}")
        : $"/orgadimage?{orgId}.{DateTime.UtcNow.Ticks}";
            var onClick = IsNullOrWhiteSpace(ad.AdUrl)
        ? "onclick=\"return false;\""
        : Empty;

            return($"<div class=\"banner-ad-outer\"><a href=\"{VotePage.NormalizeUrl(ad.AdUrl)}\"" +
                   $" {onClick} target=\"ad\"><img src=\"{src}\"" +
                   " alt=\"Ad Image\"/></a><p class=\"paid-advertisement-notice\">Paid Advertisement</p>" +
                   "<hr /></div>");
        }
Exemplo n.º 9
0
 public static string Linkify(this string self, string target = "_blank", bool nofollow = true)
 {
     return(LinkifyRegex2.Replace(self, m =>
                                  $"<a href=\"{VotePage.NormalizeUrl(m.ToString())}" +
                                  $"\"{(IsNullOrWhiteSpace(target) ? Empty : $" target=\"{target}\"")}" +