예제 #1
0
        private GlossaryData dataFromRow(DataRow dr)
        {
            GlossaryData d = new GlossaryData();

            d.Id = Convert.ToInt32(dr["GlossaryDataId"]);
            d.placeholderGlossaryId = Convert.ToInt32(dr["phGlossaryId"]);
            d.isAcronym             = Convert.ToBoolean(dr["isAcronym"]);
            d.word        = dr["word"].ToString();
            d.description = dr["description"].ToString();

            return(d);
        }
예제 #2
0
        public static GlossaryData[] FromRSSItems(Rss.RssItemCollection items)
        {
            List <GlossaryData> ret = new List <GlossaryData>();

            foreach (Rss.RssItem item in items)
            {
                GlossaryData g = new GlossaryData();
                g.word        = item.Title.Trim();
                g.description = StringUtils.StripHTMLTags(item.Description.Trim());

                ret.Add(g);
            } // foreach
            return(ret.ToArray());
        }
예제 #3
0
        } // RenderEdit

        private GlossaryData[] fromJSON(string jsonString)
        {
            JsonFx.Json.JsonReader r = new JsonFx.Json.JsonReader(jsonString);
            object o = r.Deserialize();

            if (o is Dictionary <string, object> )
            {
                List <GlossaryData>         ret  = new List <GlossaryData>();
                Dictionary <string, object> dict = (o as Dictionary <string, object>);
                foreach (string dictKey in dict.Keys)
                {
                    if (dict[dictKey] is Dictionary <string, object> )
                    {
                        Dictionary <string, object> dictObj = (dict[dictKey] as Dictionary <string, object>);
                        GlossaryData newGData = new GlossaryData();
                        foreach (string objParam in dictObj.Keys)
                        {
                            if (string.Compare(objParam, "word", true) == 0)
                            {
                                newGData.word = dictObj[objParam].ToString();
                            }
                            else if (string.Compare(objParam, "text", true) == 0)
                            {
                                newGData.description = dictObj[objParam].ToString();
                            }
                            else if (string.Compare(objParam, "isAcronym", true) == 0)
                            {
                                newGData.isAcronym = Convert.ToBoolean(dictObj[objParam].ToString());
                            }
                        } // foreach
                        ret.Add(newGData);
                    }
                } // foreach
                return(ret.ToArray());
            }

            return(new GlossaryData[0]);
        }
예제 #4
0
        public string RunInlineGlossaryFilter(CmsPage pageBeingFiltered, string placeholderHtml)
        {
            try
            {
                bool enabled = CmsConfig.getConfigValue("GlossaryHighlightFilter:Enable", false); // disabled by default

                if (!enabled || CmsContext.currentEditMode == CmsEditMode.Edit)
                {
                    return(placeholderHtml);
                }

#if DEBUG
                CmsContext.currentPage.HeadSection.AddCSSStyleStatements("span.InlineGlossaryTerm { border-bottom: 1px dotted red; }");
#endif

                // -- get the glossaryID to get data for (language specific)
                int    glossaryId  = 1;
                string glossaryIds = CmsConfig.getConfigValue("GlossaryHighlightFilter:GlossaryId", "");
                try
                {
                    string[] glossaryIdsParts = glossaryIds.Split(new char[] { CmsConfig.PerLanguageConfigSplitter }, StringSplitOptions.RemoveEmptyEntries);
                    if (glossaryIdsParts.Length >= CmsConfig.Languages.Length)
                    {
                        int index = CmsLanguage.IndexOf(CmsContext.currentLanguage.shortCode, CmsConfig.Languages);
                        if (index >= 0)
                        {
                            glossaryId = Convert.ToInt32(glossaryIdsParts[index]);
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Error: GlossaryHighlightFilter is incorrectly configured!");
                }

                // -- get the glossary data from the database. The data is cached so that we don't hit the database for this info every time.
                GlossaryData[] gData;
                string         cacheKey = "GlossaryHighlightFilter_Data_" + glossaryId;
                if (!CmsContext.currentUserIsLoggedIn && System.Web.Hosting.HostingEnvironment.Cache[cacheKey] != null)
                {
                    gData = (GlossaryData[])System.Web.Hosting.HostingEnvironment.Cache[cacheKey];
                }
                else
                {
                    GlossaryDb db = new GlossaryDb();

                    if (GlossaryPlaceholderData.DataSource == GlossaryPlaceholderData.GlossaryDataSource.RssFeed)
                    {
                        gData = db.FetchRssFeedGlossaryDataFromDatabase();
                    }
                    else
                    {
                        gData = db.getGlossaryData(glossaryId);
                    }

                    if (!CmsContext.currentUserIsLoggedIn)
                    {
                        System.Web.Hosting.HostingEnvironment.Cache.Insert(cacheKey, gData, null, DateTime.Now.AddHours(1), System.Web.Caching.Cache.NoSlidingExpiration);
                    }

                    // go through longer words first (longer words/phrases are usually more specific than shorter ones)
                    gData = GlossaryData.SortByWordLength(gData, SortDirection.Descending);
                }

                // -- short-circuit processing if there aren't any glossary terms in the system.
                if (gData.Length == 0)
                {
                    return(placeholderHtml);
                }

                // -- process the placeholderHTML
                string html = placeholderHtml;

                List <string> toSurround = new List <string>();
                List <string> prefixs    = new List <string>();
                List <string> suffixs    = new List <string>();

                foreach (GlossaryData d in gData)
                {
                    int index = html.IndexOf(d.word.Trim(), StringComparison.CurrentCultureIgnoreCase);
                    if (index >= 0 && d.word.Trim().Length > 0)
                    {
                        // string safeDesc = StringUtils.AddSlashes(d.description);
                        string safeDesc = HttpUtility.HtmlEncode(d.word + ": " + d.description);
                        safeDesc = safeDesc.Replace("\n", " ");
                        safeDesc = safeDesc.Replace("\r", " ");
                        safeDesc = safeDesc.Replace("\t", " ");
                        safeDesc = safeDesc.Replace("  ", " ");

                        string prefix = "<span title=\"" + safeDesc + "\" class=\"InlineGlossaryTerm\">";
                        string suffix = "</span>";

                        toSurround.Add(d.word.Trim());
                        prefixs.Add(prefix);
                        suffixs.Add(suffix);
                    }
                } // foreach word

                html = SurroundInHtml(toSurround.ToArray(), prefixs.ToArray(), suffixs.ToArray(), html);

                return(html.ToString());
            }
            catch (Exception ex)
            {
                placeholderHtml += ("<!-- GlossaryHighlightingFilter Error: " + ex.Message + " -->");
            }

            return(placeholderHtml);
        }
예제 #5
0
        public static string GetHtmlDisplay(CmsPage page, GlossaryData[] items, GlossaryPlaceholderData placeholderData, string[] charactersWithData, string letterToDisplay)
        {
            StringBuilder html = new StringBuilder();

            html.Append("<div class=\"Glossary\">" + Environment.NewLine);
            // -- output JumpLinks

            html.Append("<div class=\"JumpLinks\">");
            string        JumpLinksSeperator = " | ";
            List <string> jumpLinks          = new List <string>();

            if (placeholderData.ViewMode == GlossaryPlaceholderData.GlossaryViewMode.PagePerLetter && letterToDisplay != "")
            {
                jumpLinks.Add("<a href=\"" + page.Url + "\" title=\"view entire glossary\">[all]</a>");
            }


            char startChar   = 'A';
            char lastChar    = 'Z'; lastChar++;
            char currentChar = startChar;

            do
            {
                string link    = "";
                bool   outputA = false;

                if (StringUtils.IndexOf(charactersWithData, currentChar.ToString(), StringComparison.CurrentCultureIgnoreCase) > -1)
                {
                    outputA = true;

                    string url = "";
                    if (placeholderData.ViewMode == GlossaryPlaceholderData.GlossaryViewMode.PagePerLetter)
                    {
                        NameValueCollection pageParams = new NameValueCollection();
                        pageParams.Add("l", currentChar.ToString());
                        url = CmsContext.getUrlByPagePath(page.Path, pageParams);
                    }
                    else if (placeholderData.ViewMode == GlossaryPlaceholderData.GlossaryViewMode.SinglePageWithJumpList)
                    {
                        url = "#letter_" + currentChar.ToString();
                    }

                    link += "<a href=\"" + url + "\">";
                }
                link += currentChar.ToString();

                if (outputA)
                {
                    link += "</a>";
                }

                jumpLinks.Add(link);
                currentChar++;
            }while (currentChar != lastChar);

            string jumpLinksHtml = String.Join(JumpLinksSeperator, jumpLinks.ToArray());

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

            // -- output terms
            switch (placeholderData.ViewMode)
            {
            case GlossaryPlaceholderData.GlossaryViewMode.PagePerLetter:
                if (letterToDisplay == "")
                {
                    startChar = 'A';
                    lastChar  = 'Z'; lastChar++;
                }
                else
                {
                    startChar = letterToDisplay[0];
                    lastChar  = letterToDisplay[0]; lastChar++;
                }
                break;

            case GlossaryPlaceholderData.GlossaryViewMode.SinglePageWithJumpList:
                startChar = 'A';
                lastChar  = 'Z'; lastChar++;
                break;

            default:
                throw new ArgumentException("invalid GlossaryViewMode");
            } // switch viewmode


            currentChar = startChar;
            html.Append("<table class=\"glossaryitems\">");
            do
            {
                html.Append("<tr><td class=\"LetterHeading\" colspan=\"2\">");
                html.Append("<a name=\"letter_" + currentChar.ToString() + "\"></a>");
                html.Append("<h2>" + currentChar + "</h2>");
                html.Append("</td></tr>" + Environment.NewLine);

                GlossaryData[] itemsToDisplay = new GlossaryData[0];
                if (placeholderData.ViewMode == GlossaryPlaceholderData.GlossaryViewMode.SinglePageWithJumpList || letterToDisplay == "")
                {
                    itemsToDisplay = GlossaryData.getItemsStartingWithChar(items, currentChar);
                }
                else if (placeholderData.ViewMode == GlossaryPlaceholderData.GlossaryViewMode.PagePerLetter && letterToDisplay != "")
                {
                    itemsToDisplay = GlossaryData.getItemsStartingWithChar(items, currentChar);
                }
                else if (placeholderData.ViewMode == GlossaryPlaceholderData.GlossaryViewMode.PagePerLetter)
                {
                    itemsToDisplay = items;
                }


                bool oddRow = true;
                foreach (GlossaryData item in itemsToDisplay)
                {
                    string cssClass = "even";
                    if (oddRow)
                    {
                        cssClass = "odd";
                    }
                    html.Append("<tr class=\"" + cssClass + "\">");
                    html.Append("<td class=\"word " + cssClass + "\">" + item.word + "</td>");
                    html.Append("<td class=\"description " + cssClass + "\">" + item.description + "</td>");
                    html.Append("</tr>" + Environment.NewLine);
                    oddRow = !oddRow;
                } // foreach glossarydata item

                currentChar++;
            } while (currentChar != lastChar);

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

            return(html.ToString());
        }