public string GetItemSummary(IArticle article)
        {
            string summary = HttpUtility.HtmlDecode(article.Summary);

            summary = SearchSummaryUtil.GetTruncatedSearchSummary(article.Summary);
            return(HttpUtility.HtmlDecode(summary));
        }
Beispiel #2
0
        public override object GetFieldValue(I___BasePage indexItem)
        {
            var generalContentPage = indexItem as IGeneral_Content_Page;

            if (generalContentPage != null)
            {
                return(SearchSummaryUtil.GetTruncatedSearchSummary(generalContentPage.Summary));
            }

            IArticle articleItem = indexItem as IArticle;

            if (articleItem != null)
            {
                return(SearchSummaryUtil.GetTruncatedSearchSummary(articleItem.Summary));
            }

            return(SearchSummaryUtil.GetTruncatedSearchSummary(indexItem.Body));
        }
        public string GetEmailSearchBody(string senderEmail, string senderName, IEnumerable <string> resultIDs, string message, string queryTerm, string queryUrl)
        {
            string emailHtml = string.Empty;

            try
            {
                var htmlEmailTemplate = HtmlEmailTemplateFactory.Create("_BaseEmail");
                var searchTemplate    = HtmlEmailTemplateFactory.Create("EmailFriendSearch");
                var searchRow         = HtmlEmailTemplateFactory.Create("EmailFriendSearchRow");
                var searchAuthor      = HtmlEmailTemplateFactory.Create("EmailFriendSearchAuthor");

                if (htmlEmailTemplate == null ||
                    searchRow == null ||
                    searchTemplate == null ||
                    searchAuthor == null)
                {
                    return(null);
                }

                //main email information
                var siteRoot = SiteRootContext.Item;
                emailHtml = htmlEmailTemplate.Html.Replace("#Body_Content#", searchTemplate.Html);
                var footerContent = GlobalService.GetItem <IEmail_Config>(Constants.ScripEmailConfig);
                var replacements  = new Dictionary <string, string>
                {
                    ["#Environment#"]       = SiteSettings.GetSetting("Env.Value", string.Empty),
                    ["#Date#"]              = DateTime.Now.ToString("dddd, d MMMM yyyy"),
                    ["#RSS_Link_URL#"]      = siteRoot?.RSS_Link.GetLink(),
                    ["#LinkedIn_Link_URL#"] = siteRoot?.LinkedIn_Link.GetLink(),
                    ["#Twitter_Link_URL#"]  = siteRoot?.Twitter_Link.GetLink(),
                    ["#sender_name#"]       = senderName,
                    ["#sender_email#"]      = senderEmail,
                    ["#query_url#"]         = queryUrl,
                    ["#Logo_URL#"]          = (siteRoot?.Email_Logo != null)
                                                                ? GetMediaURL(siteRoot.Email_Logo.MediaId.ToString())
                                                                : string.Empty,
                    ["#RssLogo#"] = (siteRoot?.RSS_Logo != null)
                                                                ? GetMediaURL(siteRoot.RSS_Logo.MediaId.ToString())
                                                                : string.Empty,
                    ["#LinkedinLogo#"] = (siteRoot?.Linkedin_Logo != null)
                                                                ? GetMediaURL(siteRoot.Linkedin_Logo.MediaId.ToString())
                                                                : string.Empty,
                    ["#TwitterLogo#"] = (siteRoot?.Twitter_Logo != null)
                                                                ? GetMediaURL(siteRoot.Twitter_Logo.MediaId.ToString())
                                                                : string.Empty,
                    ["#personal_message#"] = (!string.IsNullOrEmpty(message))
                                                                ? $"\"{message}\""
                                                                : string.Empty,
                    ["#Footer_Content#"] = GetValue(footerContent?.Email_A_Friend_Footer_Content)
                                           .ReplacePatternCaseInsensitive("#SENDER_EMAIL#", senderEmail),
                    ["#notice_message#"]      = TextTranslator.Translate("Search.EmailPopout.Notice"),
                    ["#search_query#"]        = queryTerm,
                    ["#see_more#"]            = TextTranslator.Translate("Search.SeeMore"),
                    ["#sender_name_message#"] = !string.IsNullOrEmpty(message)
                                                                ? TextTranslator.Translate("Search.Message").Replace("#SENDER_NAME#", senderName)
                                                                : string.Empty
                };

                //search results
                StringBuilder resultBody = new StringBuilder();
                int           j          = 0;
                foreach (string id in resultIDs)
                {
                    Guid g;
                    if (!Guid.TryParse(id, out g))
                    {
                        continue;
                    }

                    var result = GlobalService.GetItem <I___BasePage>(g);
                    if (result == null)
                    {
                        continue;
                    }

                    //article authors
                    var    article      = GlobalService.GetItem <IArticle>(g);
                    bool   hasAuthors   = article != null && article.Authors.Any();
                    string byline       = TextTranslator.Translate("Article.By");
                    string authorInsert = (hasAuthors)
                                                        ? searchAuthor.Html
                                          .ReplacePatternCaseInsensitive("#article_authorBy#", (!string.IsNullOrEmpty(byline)) ? byline : string.Empty)
                                          .ReplacePatternCaseInsensitive("#article_author#", string.Join(",", article.Authors.Select(a => $"{a.First_Name} {a.Last_Name}")))
                                                        : string.Empty;

                    var row = searchRow.Html.Replace("#result_publication#", SiteRootContext?.Item?.Publication_Name)
                              .ReplacePatternCaseInsensitive("#result_title#", result.Title)
                              .ReplacePatternCaseInsensitive("#result_summary#", SearchSummaryUtil.GetTruncatedSearchSummary(result.Body))
                              .ReplacePatternCaseInsensitive("#result_url#", $"{HttpContext.Current.Request.Url.Scheme}://{HttpContext.Current.Request.Url.Host}{result._Url}")
                              .ReplacePatternCaseInsensitive("#author_insert#", authorInsert);

                    resultBody.Append(row);
                    j++;
                }
                replacements["#result_count#"] = j.ToString();
                replacements["#result_list#"]  = resultBody.ToString();

                emailHtml = emailHtml.ReplacePatternCaseInsensitive(replacements);
            }
            catch (Exception ex)
            {
            }
            return(emailHtml);
        }