/// <summary>
        /// Renders the SideNavigation control to the HtmlTextWriter
        /// </summary>
        /// <param name="writer"></param>
        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            CmsPage currentPage = CmsContext.currentPage;
            CmsPage homePage    = CmsContext.HomePage;

            if (currentPage.Id == homePage.Id)
            {
                writer.Write("<div id=\"SideNav\"></div>");
                return;
            }

            // -- get the secondLevelMainPage
            CmsPage secondLevelMainPage = currentPage;

            while (secondLevelMainPage.Level > 1)
            {
                secondLevelMainPage = secondLevelMainPage.ParentPage;
            }

            int maxLevels = 100;

            maxLevels = CmsConfig.getConfigValue("SideNavMaxLevels", maxLevels);

            bool outputAllChildren = CmsControlUtils.getControlParameterKeyValue(CmsContext.currentPage, this, "OutputAllChildren", false);

            string html = "<div id=\"SideNav\">";

            if (secondLevelMainPage.ChildPages.Length > 0)
            {
                html += "<ul class=\"level0\">" + Environment.NewLine + recursiveRender(secondLevelMainPage, 0, maxLevels, outputAllChildren) + "\n</ul>" + Environment.NewLine;
            }
            html += "</div>";

            writer.Write(html);
        }         // Render
        private string getItemDisplay(IndexableFileInfo fileInfo, string defaultOutputTemplate)
        {
            /*
             * Item Output Template String Format:
             * {0} = Page's Title
             * {1} = Page's MenuTitle
             * {2} = Page's relative URL
             * {3} = the search string snippet to display for this page
             * {4} = Page's breadcrumb created using MenuTitle's, concatenated using ' > ' spacers
             * {5} = "odd" or "even"
             *
             */

            CmsPage targetPage = getPageFromIndex(fileInfo);

            // allow per-template ItemTemplates
            string itemOutputTemplate = CmsControlUtils.getControlParameterKeyValue(CmsContext.currentPage, this, "ItemTemplate_" + targetPage.TemplateName, defaultOutputTemplate);

            string url = targetPage.Url;

            if (fileInfo.FilenameParameters != "")
            {
                if (url.IndexOf("?") > -1)
                {
                    url += "&" + fileInfo.FilenameParameters;
                }
                else
                {
                    url += "?" + fileInfo.FilenameParameters;
                }
            }

            string ItemBreadcrumb = getItemBreadcrumbOutput(targetPage);

            string OddOrEven = "even";

            if (oddItem)
            {
                OddOrEven = "odd";
            }

            oddItem = !oddItem;

            try
            {
                string ret = String.Format(itemOutputTemplate, targetPage.Title, targetPage.MenuTitle, url, StringUtils.StripHTMLTags(fileInfo.Contents), ItemBreadcrumb, OddOrEven);
                return(ret);
            }
            catch (Exception fEx)
            {
                throw new Exception("Search Item Display Template error (url: \"" + url + "\"); template: (" + itemOutputTemplate + ")");
            }
            return("");
        }
        protected override void Render(HtmlTextWriter writer)
        {
            StringBuilder html = new StringBuilder();

            /// ORASECOM river basin SWISH documents:  http://www.sadcwaterhub.org/documents/feed?source_tid_op=or&type_tid_op=or&icp_tid_op=or&rbo_tid_op=or&river_basin_tid_op=or&river_basin_tid[0]=68&title=
            string swh = "http://www.sadcwaterhub.org/documents/feed"; //all documents feed
            string url = CmsControlUtils.getControlParameterKeyValue(CmsContext.currentPage, this, "rssurl", swh);

            int cacheDuration_hours = CmsControlUtils.getControlParameterKeyValue(CmsContext.currentPage, this, "cacheduration_hours", 12);

            Rss.RssFeed documentsRss;
            // the RSS feed is cached to improve performance.
            System.Web.Caching.Cache Cache = System.Web.Hosting.HostingEnvironment.Cache;

            if (cacheDuration_hours >= 0 && Cache[url] != null)
            {
                documentsRss = (Rss.RssFeed)Cache[url];
            }
            else
            {
                documentsRss = Rss.RssFeed.Read(url);

                // add it to the cache
                if (cacheDuration_hours >= 0)
                {
                    Cache.Insert(url, documentsRss, null, DateTime.Now.AddHours(cacheDuration_hours), System.Web.Caching.Cache.NoSlidingExpiration);
                }
            }

            if (documentsRss.Channels.Count == 0)
            {
                html.Append("<em>Error: could not retrieve Documents RSS from " + url + "</em>");
            }
            else
            {
                FileLibraryAggregator2.FileAggItem[] files = FileLibraryAggregator2.FileAggItem.FromRSSItems(documentsRss.Channels[0].Items);

                files = FileLibraryAggregator2.FileAggItem.RemoveDuplicates(new List <FileLibraryAggregator2.FileAggItem>(files));
                files = FileLibraryAggregator2.FileAggItem.SortFilesByTitle(files);


                FileLibraryAggregator2.RenderParameters renderParameters = new FileLibraryAggregator2.RenderParameters();
                renderParameters.fileLinkMode   = FileLibraryAggregator2.RenderParameters.FileLinkMode.LinkToFile;
                renderParameters.ListingTitle   = CmsControlUtils.getControlParameterKeyValue(CmsContext.currentPage, this, "listingtitle", renderParameters.ListingTitle);
                renderParameters.ShowByCategory = CmsControlUtils.getControlParameterKeyValue(CmsContext.currentPage, this, "showbycategory", renderParameters.ShowByCategory);


                html.Append(FileLibraryAggregator2.RenderToHtmlList(files, renderParameters, false));
            } // else
            writer.Write(html.ToString());
        }
        protected override void Render(HtmlTextWriter writer)
        {
            StringBuilder html = new StringBuilder();

            string swh = "http://www.sadcwaterhub.org/glossary/feed?lang_tid[0]=2";
            string url = CmsControlUtils.getControlParameterKeyValue(CmsContext.currentPage, this, "rssurl", swh);

            int cacheDuration_hours = CmsControlUtils.getControlParameterKeyValue(CmsContext.currentPage, this, "cacheduration_hours", 12);

            System.Web.Caching.Cache Cache = System.Web.Hosting.HostingEnvironment.Cache;

            Rss.RssFeed glossaryRss;
            // the RSS feed is cached to improve performance.
            if (cacheDuration_hours >= 0 && Cache[url] != null)
            {
                glossaryRss = (Rss.RssFeed)Cache[url];
            }
            else
            {
                glossaryRss = Rss.RssFeed.Read(url);

                // add it to the cache
                if (cacheDuration_hours >= 0)
                {
                    Cache.Insert(url, glossaryRss, null, DateTime.Now.AddHours(cacheDuration_hours), System.Web.Caching.Cache.NoSlidingExpiration);
                }
            }

            if (glossaryRss.Channels.Count == 0)
            {
                html.Append("<em>Error: could not retrieve Glossary from SADC Water Hub</em>");
            }
            else
            {
                GlossaryData[]          items  = ToGlossaryData(glossaryRss.Channels[0].Items);
                GlossaryPlaceholderData phData = new GlossaryPlaceholderData();
                phData.SortOrder = GlossaryPlaceholderData.GlossarySortOrder.byWord;
                phData.ViewMode  = GlossaryPlaceholderData.GlossaryViewMode.PagePerLetter;

                string[] charsWithData   = getCharsWithData(items);
                string   letterToDisplay = Glossary.getLetterToDisplay(phData);

                if (letterToDisplay != "")
                {
                    items = GlossaryData.getItemsStartingWithChar(items, letterToDisplay[0]);
                }

                html.Append(Glossary.GetHtmlDisplay(CmsContext.currentPage, items, phData, charsWithData, letterToDisplay));
            } // else
            writer.Write(html.ToString());
        }
        protected override void Render(HtmlTextWriter writer)
        {
            DateTime currDateTime = DateTime.Now;
            int      count        = CmsControlUtils.getControlParameterKeyValue(CmsContext.currentPage, this, "count", 3);

            CmsLanguage lang = CmsContext.currentLanguage;
            List <EventCalendarDb.EventCalendarDetailsData> list = new EventCalendarDb().fetchUpcomingEventDetails(currDateTime, lang, count);

            StringBuilder html = new StringBuilder("<div class=\"UpcomingEvents\">");

            html.Append(renderUpcomingEventsHeader(lang));
            html.Append(renderUpcomingEventsContent(lang, list));
            html.Append("</div>");

            writer.Write(html.ToString());
        }
Esempio n. 6
0
        /// <summary>
        /// Retrieve the CmsPage (should be a calendar page) by reading the page ID from
        /// ##RenderControl(_system/SimpleCalendar calendarpage="...")##
        /// </summary>
        /// <returns></returns>
        protected CmsPage getCalendarPage()
        {
            int calendarPageId = CmsControlUtils.getControlParameterKeyValue(CmsContext.currentPage, this, "calendarpage", -1);

            if (calendarPageId == -1)
            {
                throw new Exception("CMS Control parameter for 'SimpleCalendar' not found: 'calendarpage'");
            }

            CmsPage page = CmsContext.getPageById(calendarPageId);

            if (page == null || page.TemplateName == null || !page.hasPlaceholder("EventCalendarAggregator"))
            {
                throw new Exception("##RenderControl(_system/SimpleCalendar calendarpage=\"...\")## is not a EventCalendarAggregator.");
            }

            return(page);
        }
        /// <summary>
        /// renders the MostRecentNewsItem control to the HtmlTextWriter
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="page"></param>
        /// <param name="identifier"></param>
        /// <param name="paramList"></param>
        protected override void Render(HtmlTextWriter writer)
        {
            /// Parameters:
            /// [newsIndex] index to display (integer)
            /// [template]: Output Template
            ///     template parameters: url, summaryOutput, newsArticleDetailsPage.Title, dateOfNews
            ///     {0} = url
            ///     {1} = snippet
            ///     {2} = title
            ///     {3} = date
            /// [dateOutputFormat]: dateOutputFormat
            /// [summaryLength]: maxLengthOfSummary (integer)

            int    indexToDisplay     = 0;
            string template           = "{3}: <a href=\"{0}\">{2}</a><br>{1}";
            string dateOutputFormat   = "MMMM d, yyyy";
            int    maxLengthOfSummary = 115;

            if (CmsConfig.TemplateEngineVersion == CmsTemplateEngineVersion.v2)
            {
                indexToDisplay     = CmsControlUtils.getControlParameterKeyValue(CmsContext.currentPage, this, "newsIndex", indexToDisplay);
                template           = CmsControlUtils.getControlParameterKeyValue(CmsContext.currentPage, this, "template", template);
                dateOutputFormat   = CmsControlUtils.getControlParameterKeyValue(CmsContext.currentPage, this, "dateFormat", dateOutputFormat);
                maxLengthOfSummary = CmsControlUtils.getControlParameterKeyValue(CmsContext.currentPage, this, "summaryLength", maxLengthOfSummary);
                dateOutputFormat   = CmsControlUtils.getControlParameterKeyValue(CmsContext.currentPage, this, "dateOutputFormat", dateOutputFormat);
            }
            else
            {
                throw new ArgumentException("Invalid CmsTemplateEngineVersion");
            }


            CmsLanguage lang  = CmsContext.currentLanguage;
            int         count = CmsConfig.getConfigValue("MostRecentNews.Count", 1);
            List <NewsArticleDb.NewsArticleDetailsData> articleArray = new NewsArticleDb().fetchNewsDetailsByCount(lang, indexToDisplay, count);

            StringBuilder html = new StringBuilder();

            html.Append(renderHeader(lang));
            html.Append(renderContent(articleArray, lang, template, maxLengthOfSummary, dateOutputFormat));

            writer.Write(html.ToString());
        } // Render
        /// <summary>
        /// crawls up the page path to see if anything has been configured for that page.
        /// if nothing found, returns String.Empty.
        /// </summary>
        /// <param name="page"></param>
        /// <returns></returns>
        private string getImageByPagePath(CmsPage page)
        {
            CmsPage currPage      = page;
            string  notFoundValue = Guid.NewGuid().ToString();

            while (currPage.ID != -1)
            {
                string PagePath = currPage.Path;
                string keyVal   = CmsControlUtils.getControlParameterKeyValue(CmsContext.currentPage, this, PagePath, notFoundValue);
                if (keyVal != notFoundValue)
                {
                    return(keyVal);
                }

                currPage = currPage.ParentPage;
            } // while

            return(String.Empty);
        } // getImageByPagePath
        } // getImageByPagePath

        /// <summary>
        /// if nothing found, returns String.Empty
        /// </summary>
        /// <returns></returns>
        private string getRandomImage()
        {
            // -- get all the configured image vals
            string[]  configKeys    = CmsControlUtils.getControlParameterKeys(CmsContext.currentPage, this);
            ArrayList imgUrls       = new ArrayList();
            string    notFoundValue = Guid.NewGuid().ToString();

            foreach (string key in configKeys)
            {
                string val = CmsControlUtils.getControlParameterKeyValue(CmsContext.currentPage, this, key, notFoundValue);
                if (val != "" && val != notFoundValue && String.Compare(val, RandomImageKeyValue, true) != 0)
                {
                    imgUrls.Add(val);
                }
            } // foreach

            // -- select the image at random
            if (imgUrls.Count > 0)
            {
                int randomUrlIndex = (new System.Random()).Next(0, imgUrls.Count - 1);
                return(imgUrls[randomUrlIndex].ToString());
            }
            return(String.Empty);
        } // getRandomImage
        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            CmsPage currentPage = CmsContext.currentPage;

            /*
             * Item Output Template String Format:
             * {0} = Page's Title
             * {1} = Page's MenuTitle
             * {2} = Page's relative URL
             * {3} = the search string snippet to display for this page
             * {4} = Page's breadcrumb created using MenuTitle's, concatenated using ' > ' spacers
             * {5} = "odd" or "even"
             *
             */
            string defaultItemTemplate = "<div class=\"SearchResultItem {5}\"><a class=\"SearchResultItemLink\" href=\"{2}\">{0}</a><br/><blockquote class=\"SearchResultInfo\"><div class=\"Snippet\">{3}</div><div class=\"SearchResultItemBreadcrumb\">{4}</div></blockquote></div>";
            string itemOutputTemplate  = CmsControlUtils.getControlParameterKeyValue(CmsContext.currentPage, this, "ItemTemplate", defaultItemTemplate);

            string        action = PageUtils.getFromForm("action", "");
            StringBuilder html   = new StringBuilder();

            html.Append("<div class=\"SearchResults\">");

            if (action == "re-Index All Pages" || action.ToLower() == "reindexall")
            {
                ReIndexAllPages();
                html.Append("<p><strong>All Pages have been re-indexed</strong><p>");
            }

            string noQuery = Guid.NewGuid().ToString();
            string query   = PageUtils.getFromForm("q", noQuery);

            html.Append("<div class=\"SearchBox\">");
            // -- output search box
            string formId = "SearchResults";

            html.Append(currentPage.getFormStartHtml(formId));
            if (query == noQuery)
            {
                html.Append(PageUtils.getInputTextHtml("q", "queryBox", "", 20, 255));
            }
            else
            {
                html.Append(PageUtils.getInputTextHtml("q", "queryBox", query, 20, 255));
            }
            html.Append("<input type=\"submit\" value=\"search\">");

            // -- output doIndex button
            if (CmsContext.currentUserIsSuperAdmin)
            {
                html.Append(" Admin:<input type=\"submit\" name=\"action\" value=\"re-Index All Pages\">");
            }
            html.Append(currentPage.getFormCloseHtml(formId));
            html.Append("</div>");
            html.Append("<p>");

            LuceneKeywordSearch search = new LuceneKeywordSearch(IndexStorageDirectory, SpellCheckIndexStorageDirectory);

            if (query != noQuery)
            {
                // -- do the search with keyword highlighting
                IndexableFileInfo[] fileInfos = search.doSearch(query, query);

                fileInfos = getFileInfosForCurrentLanguage(fileInfos);

                // -- output the results
                if (fileInfos.Length < 1)
                {
                    // -- no results
                    html.Append("<strong>Your search for \"" + query + "\" returned no results</strong>");
                    // -- get spelling suggestion
                    string spellingSuggestion = search.getSpellingSuggestion(query);
                    if (spellingSuggestion.Trim() != query.Trim())
                    {
                        NameValueCollection p = new NameValueCollection();
                        p.Add("q", spellingSuggestion);
                        string newSearchUrl = CmsContext.getUrlByPagePath(CmsContext.currentPage.Path, p);
                        html.Append("<p><font color=\"#cc0000\">Did you mean:</font> \"<a href=\"" + newSearchUrl + "\">" + spellingSuggestion + "</a>\" <font color=\"#cc0000\">?</font></p>");
                    }
                }
                else
                {
                    html.Append("<strong>Your search for \"" + query + "\" returned " + fileInfos.Length + " results</strong><p>");
                    html.Append("<p>" + getPagerOutput(fileInfos) + "</p>");

                    int startAtItemNumber = PageUtils.getFromForm("num", 0);
                    if (startAtItemNumber >= fileInfos.Length)
                    {
                        startAtItemNumber = fileInfos.Length - 1;
                    }
                    int endAt = Math.Min(startAtItemNumber + numItemsPerPage - 1, fileInfos.Length - 1);

                    if (startAtItemNumber == 0 && endAt == 0 && fileInfos.Length == 1)
                    {
                        html.Append(getItemDisplay(fileInfos[0], itemOutputTemplate));
                    }
                    else
                    {
                        for (int i = startAtItemNumber; i <= endAt; i++)
                        {
                            if (endAt <= 0)
                            {
                                break;
                            }
                            IndexableFileInfo fileInfo = fileInfos[i];
                            html.Append(getItemDisplay(fileInfo, itemOutputTemplate));
                        } // for

                        html.Append("<p>" + getPagerOutput(fileInfos) + "</p>");
                    } // else
                }
            }             // if query != noQuery

            html.Append("</div>");

            writer.WriteLine(html.ToString());
        }         // Render
Esempio n. 11
0
        protected override void Render(HtmlTextWriter writer)
        {
            StringBuilder html = new StringBuilder();

            /// ORASECOM river basin SWISH news:  http://www.sadcwaterhub.org/articles/feed?keywords=orange%20OR%20ORASECOM%20OR%20%22Orange-Senqu%22
            string rssurl = "http://www.sadcwaterhub.org/articles/feed"; //all articles feed
            int    cacheDuration_hours = 12;

            /// [template]: Output Template
            ///     template parameters: url, summaryOutput, newsArticleDetailsPage.Title, dateOfNews
            ///     {0} = url
            ///     {1} = snippet
            ///     {2} = title
            ///     {3} = date
            /// [dateOutputFormat]: dateOutputFormat
            /// [summaryLength]: maxLengthOfSummary (integer)
            string itemTemplate       = "<div class=\"RSSNewsItem\">{3}: <a href=\"{0}\">{2}</a><br>{1}</div>";
            string dateOutputFormat   = "MMMM d, yyyy";
            int    maxLengthOfSummary = 115;

            if (CmsConfig.TemplateEngineVersion == CmsTemplateEngineVersion.v2)
            {
                rssurl = CmsControlUtils.getControlParameterKeyValue(CmsContext.currentPage, this, "rssurl", rssurl);
                cacheDuration_hours = CmsControlUtils.getControlParameterKeyValue(CmsContext.currentPage, this, "cacheduration_hours", cacheDuration_hours);
                itemTemplate        = CmsControlUtils.getControlParameterKeyValue(CmsContext.currentPage, this, "template", itemTemplate);
                dateOutputFormat    = CmsControlUtils.getControlParameterKeyValue(CmsContext.currentPage, this, "dateFormat", dateOutputFormat);
                maxLengthOfSummary  = CmsControlUtils.getControlParameterKeyValue(CmsContext.currentPage, this, "summaryLength", maxLengthOfSummary);
                dateOutputFormat    = CmsControlUtils.getControlParameterKeyValue(CmsContext.currentPage, this, "dateOutputFormat", dateOutputFormat);
            }
            else
            {
                throw new ArgumentException("Invalid CmsTemplateEngineVersion");
            }

            System.Web.Caching.Cache Cache = System.Web.Hosting.HostingEnvironment.Cache;
            Rss.RssFeed newsRss;
            // the RSS feed is cached to improve performance.
            if (cacheDuration_hours >= 0 && Cache[rssurl] != null)
            {
                newsRss = (Rss.RssFeed)Cache[rssurl];
            }
            else
            {
                newsRss = Rss.RssFeed.Read(rssurl);

                // add it to the cache
                if (cacheDuration_hours >= 0)
                {
                    Cache.Insert(rssurl, newsRss, null, DateTime.Now.AddHours(cacheDuration_hours), System.Web.Caching.Cache.NoSlidingExpiration);
                }
            }

            if (newsRss.Channels.Count == 0)
            {
                html.Append("<em>Error: could not retrieve News RSS from " + rssurl + "</em>");
            }
            else if (newsRss.Channels.Count > 0 && newsRss.Channels[0].Items.Count == 0)
            {
                html.Append("<em>There are no news items available to view</em>");
            }
            else
            {
                html.Append(GetArticleListHtml(newsRss.Channels[0].Items, itemTemplate, maxLengthOfSummary, dateOutputFormat));
            } // else
            writer.Write(html.ToString());
        }
        } // getParameterValue

        public static string getParameterValue(CmsPage page, CmsControlDefinition controlDefinition, string key, string defaultValue)
        {
            return(CmsControlUtils.getControlParameterKeyValue(page, controlDefinition, key, defaultValue));
        }
Esempio n. 13
0
 private string getUnSelectedImage(CmsPage controlsPage)
 {
     return(CmsControlUtils.getControlParameterKeyValue(controlsPage, this, "UnSelectedImage", ""));
 }
Esempio n. 14
0
 private string getSelectedParentPagePath(CmsPage controlsPage)
 {
     return(CmsControlUtils.getControlParameterKeyValue(controlsPage, this, "SelectedParentPagePath", ""));
 }