Exemplo n.º 1
0
        /// <summary>
        /// Return the html with any included modules inserted into the html. Script data is not included in html.
        /// </summary>
        /// <param name="pageContent"></param>
        /// <returns>Formatted Html Content with Module Contents and a list of script html</returns>
        public static PageDataCollection GetFormattedPageContentAndScripts(string pageContent)
        {
            var collection = new PageDataCollection()
            {
                HtmlFormatted = pageContent,
                ScriptContents = new List<string>(),
                StylesContents = new List<string>()
            };

            // Save a lookup
            if (String.IsNullOrEmpty(pageContent))
            {
                return collection;
            }

            // pull everything in-between brackets. Ex : [text] will extract "text".
            const string pattern = @"\[(.*?)\]";
            var matches = Regex.Matches(pageContent, pattern);

            using (var context = new DataContext())
            {
                // Run through each matched tag and replace with module html if found. Otherwise leave the tag alone
                foreach (Match m in matches)
                {
                    string tag = m.Groups[1].ToString();

                    var module = context.ContentModules.Where(x => x.ModuleName == tag).FirstOrDefault();
                    if (module != null)
                    {
                        string htmlContent = String.Format("<div class='shortCodeInsert sortableModule' data-name='{0}'>{1}</div>", module.ModuleName, module.HTMLContent);

                        collection.ScriptContents.Add(module.JSContent);
                        collection.StylesContents.Add(module.CSSContent);

                        pageContent = pageContent.Replace("[" + tag + "]", htmlContent);
                    }
                    // Otherwise check dynamic modules
                    else
                    {

                        ShortCodeObject shortCode = GetFormattedShortCodeObject(tag);

                        DynamicModules dm = DynamicModules.Instance;
                        if (dm.GetDynamicModuleList().ContainsKey(shortCode.Name))
                        {
                            var list = dm.GetDynamicModuleList();
                            if (list.ContainsKey(shortCode.Name))
                            {
                                string htmlContent = String.Format("<div class='dynamicCodeInsert sortableModule {2}' data-name='{0}' data-tag='{3}'>{1}</div>", tag,
                                                           list[shortCode.Name].GetHtml(shortCode.Parameters), list[shortCode.Name].GetCSSClass(), tag);

                                pageContent = pageContent.Replace("[" + tag + "]", htmlContent);
                            }
                        }
                    }
                }
            }

            // update the collection's html entity once we're done parsing
            collection.HtmlFormatted = pageContent;

            return collection;
        }
        private void init()
        {
            TheTemplate = GetContentTemplate(ThePage.Template);

            PageData = ContentUtils.GetFormattedPageContentAndScripts(ThePage.HTMLContent);
        }