Exemplo n.º 1
0
        public static String LinkUrl(this Sitecore.Data.Fields.LinkField lf)
        {
            switch (lf.LinkType.ToLower())
            {
            case "internal":
                // Use LinkMananger for internal links, if link is not empty
                return(lf.TargetItem != null?Sitecore.Links.LinkManager.GetItemUrl(lf.TargetItem) : string.Empty);

            case "media":
                // Use MediaManager for media links, if link is not empty
                return(lf.TargetItem != null?Sitecore.Resources.Media.MediaManager.GetMediaUrl(lf.TargetItem) : string.Empty);

            case "external":
                // Just return external links
                return(lf.Url);

            case "anchor":
                // Prefix anchor link with # if link if not empty
                return(!string.IsNullOrEmpty(lf.Anchor) ? "#" + lf.Anchor : string.Empty);

            case "mailto":
                // Just return mailto link
                return(lf.Url);

            case "javascript":
                // Just return javascript
                return(lf.Url);

            default:
                // Just please the compiler, this
                // condition will never be met
                return(lf.Url);
            }
        }
Exemplo n.º 2
0
        private bool Is_Included(Item currentitem)
        {
            Sitecore.Data.Fields.LinkField link = currentitem.Fields["Destination"];
            var           item  = Sitecore.Context.Database.GetItem(link.TargetID);
            CheckboxField field = (CheckboxField)item.Fields["IncludeInNavigation"];

            return(field.Checked);
        }
Exemplo n.º 3
0
        public List <Item> indexSitecoreContent()
        {
            // ID blogTemplateId = new Sitecore.Data.ID("{48587868-4A19-48BB-8FC9-F1DD31CB6C8E}");
            //var index = Sitecore.ContentSearch.ContentSearchManager.GetIndex("sitecore_master_index");
            //List<Item> results = new List<Item>();

            //using (Sitecore.ContentSearch.IProviderSearchContext context = index.CreateSearchContext())
            //{
            //    //var searchResults = context.GetQueryable<SearchResultItem>().Where(x => x.Content.Contains("Sitecore"));
            //    var searchResults = context.GetQueryable<SearchResultItem>().Take(10);
            //    results = (List<Item>)searchResults;
            //}



            #region Indexing

            // Get the indexes files from the "lucene_Index" folder
            string[] filePaths = System.IO.Directory.GetFiles(_luceneDir);

            // Delete all the indexes from "lucene_Index" folder
            foreach (string filePath in filePaths)
            {
                File.Delete(filePath);
            }


            //Create Directory for Indexes
            //There are 2 options, FS or RAM
            //Step 1: Declare Index Store


            //Now we need Analyzer
            //An Analyzer builds TokenStreams, which analyze text. It thus represents a policy for extracting index terms from text.
            //In general, any analyzer in Lucene is tokenizer + stemmer + stop-words filter.
            //Tokenizer splits your text into chunks-For example, for phrase "I am very happy" it will produce list ["i", "am", "very", "happy"]
            // stemmer:-piece of code responsible for “normalizing” words to their common form (horses => horse, indexing => index, etc)
            //Stop words are the most frequent and almost useless words
            Analyzer analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30);

            //Need an Index Writer to write the output of Analysis to Index
            IndexWriter writer = new IndexWriter(_directory, analyzer, IndexWriter.MaxFieldLength.UNLIMITED);

            // Get the data to index for search
            Item ExternalLinksFolder = Sitecore.Context.Database.GetItem("{6BD289C4-A964-4915-A769-A79C897D1746}");

            string htmlContent = string.Empty;

            // string[] ExternalLinksHtmlContent = new string[ExternalLinksFolder.Children.Count];
            // string ExternalPageHtmlContent;
            int count = 0;
            Sitecore.Data.Fields.ImageField imageField = null;
            SitecoreFields.LinkField        linkfield  = null;
            string externalurl;
            // web page declaring
            var htmlWeb = new HtmlWeb();
            HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
            string webPageTitle;
            string webPageContent;


            // end declaring
            foreach (Item externalLinkItem in ExternalLinksFolder.Children)
            {
                Document doc = new Document();
                linkfield   = externalLinkItem.Fields["ExternalURL"];
                externalurl = linkfield.Url;

                imageField = externalLinkItem.Fields["Image"];

                // webpage Title field
                LargestImage largestImage = new LargestImage();
                HtmlAgilityPack.HtmlDocument htmlDocument = new HtmlAgilityPack.HtmlDocument();
                htmlDocument   = htmlWeb.Load(externalurl);
                webPageTitle   = GetWebPageTitle(htmlDocument);
                webPageContent = GetPageContent(htmlDocument);
                largestImage   = GetLargestWebPageSec(htmlDocument, externalurl);
                // image field
                if (largestImage.imgSrc == "") // populate image attributes from sitecore image field if there is no image found on the external web page
                {
                    largestImage.imgSrc = Sitecore.Resources.Media.MediaManager.GetMediaUrl(imageField.MediaItem);
                    largestImage.imgAlt = imageField.Alt;
                }

                if (webPageTitle == "") // populate title from sitecore if webpage has no title or h1 tags
                {
                    webPageTitle = externalLinkItem.Fields["Title"].Value;
                }

                if (webPageContent == "")
                {
                    webPageContent = externalLinkItem.Fields["PageContent"].Value;
                }

                // end image field
                doc.Add(new Field("External_WebPage_Content", webPageContent, Field.Store.YES, Field.Index.ANALYZED));
                doc.Add(new Field("External_WebPage_Title", webPageTitle, Field.Store.YES, Field.Index.ANALYZED));
                doc.Add(new Field("External_WebPage_Url", externalurl, Field.Store.YES, Field.Index.NOT_ANALYZED));
                doc.Add(new Field("External_WebPage_ImageSrc", largestImage.imgSrc, Field.Store.YES, Field.Index.NOT_ANALYZED));
                doc.Add(new Field("External_WebPage_ImageAlt", largestImage.imgAlt, Field.Store.YES, Field.Index.NOT_ANALYZED));

                writer.AddDocument(doc);
                count++;
            }

            writer.Optimize();
            writer.Commit();
            writer.Dispose();
            #endregion

            return(results);
        }
Exemplo n.º 4
0
        private void Page_Load(object sender, EventArgs e)
        {
            Item      currentItem = Sitecore.Context.Item;
            ChildList childItems  = currentItem.Children;
            string    pageURL     = Sitecore.Links.LinkManager.GetItemUrl(currentItem);
            string    pageTitle   = "Home";

            try
            {
                //Set Video data from Home Page data item
                string videoEmbedCode = "";
                videoEmbedCode = currentItem.Fields["Video Embed URL"].Value;

                litOpenVideoSpan.Text  = String.Format("<span onclick=\"jQuery('#ytplayer').attr('src','{0}');jQuery('.video-container').show();jQuery('.vid-player-img').hide();jQuery('.main-video').show();\">", videoEmbedCode);
                litCloseVideoSpan.Text = "</span>";

                imgHomeVideo.Item = currentItem;
            }
            catch (Exception ex) { }
            List <Item> meetingItems = Sitecore.Context.Item.Axes.SelectItems("descendant::*[@@templatename='Meeting']").Where(x => DateUtil.ParseDateTime(x["Meeting Date"], DateTime.MaxValue) >= DateTime.UtcNow.Date).OrderBy(x => x["Meeting Date"]).Take(3).ToList <Item>();

            if (meetingItems != null && meetingItems.Any())
            {
                try {
                    Item nextMeeting = meetingItems.First();
                    litNextMeetingDate.Text     = DateUtil.ParseDateTime(nextMeeting.Fields["Meeting Date"].Value, DateTime.MaxValue).ToString("D");
                    litNextMeetingTime.Text     = nextMeeting.Fields["Meeting Time"].Value;
                    litNextMeetingLocation.Text = nextMeeting.Fields["Location"].Value;



                    try
                    {
                        Sitecore.Data.Fields.LinkField viewMapLink = (Sitecore.Data.Fields.LinkField)nextMeeting.Fields["Map Link"];

                        string navUrl = viewMapLink.Url;

                        if (navUrl != "")
                        {
                            lnkNextMeetingMap.NavigateUrl = navUrl;
                        }

                        Sitecore.Data.Fields.FileField fileField = ((Sitecore.Data.Fields.FileField)nextMeeting.Fields["Agenda"]);

                        if (fileField != null && nextMeeting.Fields["Agenda"].HasValue)
                        {
                            string agendaURL = Sitecore.Resources.Media.MediaManager.GetMediaUrl(fileField.MediaItem);
                            lnkNextMeetingAgenda.NavigateUrl = agendaURL;
                        }
                    }
                    catch (Exception ex) {
                    }

                    //Bind additional meeting items to "Future" meetings section
                    if (meetingItems.Count > 1)
                    {
                        Item[] futureMeetings = meetingItems.Skip(1).ToArray();
                        rptFutureMeetings.DataSource = futureMeetings;
                        rptFutureMeetings.DataBind();
                    }
                }
                catch (Exception ex) {
                }
            }
        }