Example #1
0
        public static string ParseInDynamicPage(string stlElement, PageInfo pageInfo, string pageUrl, int channelId, int currentPageIndex, int pageCount, int totalNum, bool isPageRefresh, string ajaxDivId)
        {
            string parsedContent;

            try
            {
                var stlElementInfo = StlParserUtility.ParseStlElement(stlElement);

                if (pageCount <= 1)
                {
                    return(string.Empty);
                }

                var index  = stlElement.IndexOf(">", StringComparison.Ordinal) + 1;
                var length = stlElement.LastIndexOf("<", StringComparison.Ordinal) - index;
                if (index <= 0 || length <= 0)
                {
                    stlElement = stlElementInfo.InnerHtml;
                }
                else
                {
                    stlElement = stlElement.Substring(index, length);
                }

                parsedContent = StlPageElementParser.ParseStlPageItemsInDynamicPage(stlElement, pageInfo, pageUrl, channelId, currentPageIndex, pageCount, totalNum, isPageRefresh, ajaxDivId);
            }
            catch (Exception ex)
            {
                parsedContent = LogUtils.AddStlErrorLog(pageInfo, ElementName, stlElement, ex);
            }

            return(parsedContent);
        }
        //对“翻页项容器”(stl:pageItems)元素进行解析,此元素在生成页面时单独解析,不包含在ParseStlElement方法中。
        public static string Parse(string stlElement, PageInfo pageInfo, int channelId, int contentId, int currentPageIndex, int pageCount, int totalNum, EContextType contextType)
        {
            pageInfo.AddPageBodyCodeIfNotExists(PageInfo.Const.Jquery);
            string parsedContent;

            try
            {
                var stlElementInfo = StlParserUtility.ParseStlElement(stlElement);
                if (stlElementInfo.Attributes[Context] != null)
                {
                    contextType = EContextTypeUtils.GetEnumType(stlElementInfo.Attributes[Context]);
                }

                if (pageCount <= 1)
                {
                    return(string.Empty);
                }

                bool isXmlContent;
                var  index  = stlElement.IndexOf(">", StringComparison.Ordinal) + 1;
                var  length = stlElement.LastIndexOf("<", StringComparison.Ordinal) - index;
                if (index <= 0 || length <= 0)
                {
                    stlElement   = stlElementInfo.InnerHtml;
                    isXmlContent = true;
                }
                else
                {
                    stlElement   = stlElement.Substring(index, length);
                    isXmlContent = false;
                }

                parsedContent = StlPageElementParser.ParseStlPageItems(stlElement, pageInfo, channelId, contentId, currentPageIndex, pageCount, totalNum, isXmlContent, contextType);

                ContextInfo contextInfo = new ContextInfo(pageInfo)
                {
                    ContextType = contextType
                };
                var innerBuilder = new StringBuilder(parsedContent);
                StlParserManager.ParseInnerContent(innerBuilder, pageInfo, contextInfo);
                parsedContent = innerBuilder.ToString();
            }
            catch (Exception ex)
            {
                parsedContent =
                    LogUtils.AddStlErrorLog(pageInfo, ElementName, stlElement, ex);
            }

            return(parsedContent);
        }
Example #3
0
        public int GetPageCount(out int totalNum)
        {
            totalNum = 0;
            var pageCount = 1;

            try
            {
                //totalNum = DataProvider.DatabaseDao.GetPageTotalCount(SqlString);
                totalNum = StlDatabaseCache.GetPageTotalCount(SqlString);
                if (ListInfo.PageNum != 0 && ListInfo.PageNum < totalNum)                                                       //需要翻页
                {
                    pageCount = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(totalNum) / Convert.ToDouble(ListInfo.PageNum))); //需要生成的总页数
                }
            }
            catch (Exception ex)
            {
                LogUtils.AddStlErrorLog(_pageInfo, ElementName, _stlPageContentsElement, ex);
            }
            return(pageCount);
        }
Example #4
0
        //private readonly DataSet _dataSet;

        public StlPageSqlContents(string stlPageSqlContentsElement, PageInfo pageInfo, ContextInfo contextInfo)
        {
            _stlPageSqlContentsElement = stlPageSqlContentsElement;
            _pageInfo = pageInfo;
            try
            {
                var stlElementInfo = StlParserUtility.ParseStlElement(stlPageSqlContentsElement);

                _contextInfo = contextInfo.Clone(stlPageSqlContentsElement, stlElementInfo.InnerHtml, stlElementInfo.Attributes);

                _listInfo = ListInfo.GetListInfo(_pageInfo, _contextInfo, EContextType.SqlContent);

                _sqlString = _listInfo.QueryString;
                if (string.IsNullOrWhiteSpace(_listInfo.OrderByString))
                {
                    var pos = _sqlString.LastIndexOf(" ORDER BY ", StringComparison.OrdinalIgnoreCase);
                    if (pos > -1)
                    {
                        _sqlString = _sqlString.Substring(0, pos);
                        _listInfo.OrderByString = _sqlString.Substring(pos);
                    }
                }
                else
                {
                    if (_listInfo.OrderByString.IndexOf("ORDER BY", StringComparison.OrdinalIgnoreCase) == -1)
                    {
                        _listInfo.OrderByString = $"ORDER BY {_listInfo.OrderByString}";
                    }
                }

                //_dataSet = StlDataUtility.GetPageSqlContentsDataSet(_listInfo.ConnectionString, _listInfo.QueryString, _listInfo.StartNum, _listInfo.PageNum, _listInfo.OrderByString);
            }
            catch (Exception ex)
            {
                LogUtils.AddStlErrorLog(pageInfo, ElementName, stlPageSqlContentsElement, ex);
                _listInfo = new ListInfo();
            }
        }
Example #5
0
        private static string ParseStlElement(string stlElement, PageInfo pageInfo, ContextInfo contextInfo)
        {
            string parsedContent = null;

            var stlElementInfo = StlParserUtility.ParseStlElement(stlElement);

            if (stlElementInfo != null)
            {
                var elementName = stlElementInfo.Name;

                if (ElementsToTranslateDic.ContainsKey(elementName))
                {
                    if (ElementsToTranslateDic.TryGetValue(elementName, out var func))
                    {
                        parsedContent = func(stlElement);
                    }
                }
                else if (ElementsToParseDic.ContainsKey(elementName))
                {
                    if (stlElementInfo.IsDynamic)
                    {
                        parsedContent = StlDynamic.ParseDynamicElement(stlElement, pageInfo, contextInfo);
                    }
                    else
                    {
                        try
                        {
                            if (ElementsToParseDic.TryGetValue(elementName, out var func))
                            {
                                var contextInfoClone = contextInfo.Clone(stlElement, stlElementInfo.InnerHtml, stlElementInfo.Attributes);

                                var obj = func(pageInfo, contextInfoClone);

                                if (obj == null)
                                {
                                    parsedContent = string.Empty;
                                }
                                else if (obj is string)
                                {
                                    parsedContent = (string)obj;
                                }
                                else
                                {
                                    parsedContent = TranslateUtils.JsonSerialize(obj);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            parsedContent = LogUtils.AddStlErrorLog(pageInfo, elementName, stlElement, ex);
                        }
                    }
                }
                else
                {
                    var parsers = PluginStlParserContentManager.GetParses();
                    if (parsers.ContainsKey(elementName))
                    {
                        if (stlElementInfo.IsDynamic)
                        {
                            parsedContent = StlDynamic.ParseDynamicElement(stlElement, pageInfo, contextInfo);
                        }
                        else
                        {
                            try
                            {
                                if (parsers.TryGetValue(elementName, out var func))
                                {
                                    var context = new ParseContextImpl(stlElementInfo.OuterHtml, stlElementInfo.InnerHtml, stlElementInfo.Attributes, pageInfo, contextInfo);
                                    parsedContent = func(context);
                                }
                            }
                            catch (Exception ex)
                            {
                                parsedContent = LogUtils.AddStlErrorLog(pageInfo, elementName, stlElement, ex);
                            }
                        }
                    }
                }
            }

            return(parsedContent ?? stlElement);
        }
        public IHttpActionResult Main()
        {
            PageInfo pageInfo = null;
            var      template = string.Empty;

            try
            {
                var request = new RequestImpl();
                var form    = GetPostCollection(request);

                var isAllSites    = request.GetPostBool(StlSearch.IsAllSites.ToLower());
                var siteName      = AttackUtils.FilterSqlAndXss(request.GetPostString(StlSearch.SiteName.ToLower()));
                var siteDir       = AttackUtils.FilterSqlAndXss(request.GetPostString(StlSearch.SiteDir.ToLower()));
                var siteIds       = AttackUtils.FilterSqlAndXss(request.GetPostString(StlSearch.SiteIds.ToLower()));
                var channelIndex  = AttackUtils.FilterSqlAndXss(request.GetPostString(StlSearch.ChannelIndex.ToLower()));
                var channelName   = AttackUtils.FilterSqlAndXss(request.GetPostString(StlSearch.ChannelName.ToLower()));
                var channelIds    = AttackUtils.FilterSqlAndXss(request.GetPostString(StlSearch.ChannelIds.ToLower()));
                var type          = AttackUtils.FilterSqlAndXss(request.GetPostString(StlSearch.Type.ToLower()));
                var word          = AttackUtils.FilterSqlAndXss(request.GetPostString(StlSearch.Word.ToLower()));
                var dateAttribute = AttackUtils.FilterSqlAndXss(request.GetPostString(StlSearch.DateAttribute.ToLower()));
                var dateFrom      = AttackUtils.FilterSqlAndXss(request.GetPostString(StlSearch.DateFrom.ToLower()));
                var dateTo        = AttackUtils.FilterSqlAndXss(request.GetPostString(StlSearch.DateTo.ToLower()));
                var since         = AttackUtils.FilterSqlAndXss(request.GetPostString(StlSearch.Since.ToLower()));
                var pageNum       = request.GetPostInt(StlSearch.PageNum.ToLower());
                var isHighlight   = request.GetPostBool(StlSearch.IsHighlight.ToLower());
                var siteId        = request.GetPostInt("siteid");
                var ajaxDivId     = AttackUtils.FilterSqlAndXss(request.GetPostString("ajaxdivid"));
                template = TranslateUtils.DecryptStringBySecretKey(request.GetPostString("template"));
                var pageIndex = request.GetPostInt("page", 1) - 1;

                var templateInfo = new TemplateInfo(0, siteId, string.Empty, TemplateType.FileTemplate, string.Empty, string.Empty, string.Empty, ECharset.utf_8, false);
                var siteInfo     = SiteManager.GetSiteInfo(siteId);
                pageInfo = new PageInfo(siteId, 0, siteInfo, templateInfo, new Dictionary <string, object>())
                {
                    UserInfo = request.UserInfo
                };
                var contextInfo    = new ContextInfo(pageInfo);
                var contentBuilder = new StringBuilder(StlRequestEntities.ParseRequestEntities(form, template));

                var stlLabelList = StlParserUtility.GetStlLabelList(contentBuilder.ToString());

                if (StlParserUtility.IsStlElementExists(StlPageContents.ElementName, stlLabelList))
                {
                    var stlElement             = StlParserUtility.GetStlElement(StlPageContents.ElementName, stlLabelList);
                    var stlPageContentsElement = stlElement;
                    var stlPageContentsElementReplaceString = stlElement;

                    var whereString = DataProvider.ContentDao.GetWhereStringByStlSearch(isAllSites, siteName, siteDir, siteIds, channelIndex, channelName, channelIds, type, word, dateAttribute, dateFrom, dateTo, since, siteId, ApiRouteActionsSearch.ExlcudeAttributeNames, form);

                    var stlPageContents = new StlPageContents(stlPageContentsElement, pageInfo, contextInfo, pageNum, siteInfo.TableName, whereString);
                    var pageCount       = stlPageContents.GetPageCount(out var totalNum);
                    if (totalNum == 0)
                    {
                        return(NotFound());
                    }

                    for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++)
                    {
                        if (currentPageIndex != pageIndex)
                        {
                            continue;
                        }

                        var pageHtml     = stlPageContents.Parse(totalNum, currentPageIndex, pageCount, false);
                        var pagedBuilder = new StringBuilder(contentBuilder.ToString().Replace(stlPageContentsElementReplaceString, pageHtml));

                        StlParserManager.ReplacePageElementsInSearchPage(pagedBuilder, pageInfo, stlLabelList, ajaxDivId, pageInfo.PageChannelId, currentPageIndex, pageCount, totalNum);

                        if (isHighlight && !string.IsNullOrEmpty(word))
                        {
                            var pagedContents = pagedBuilder.ToString();
                            pagedBuilder = new StringBuilder();
                            pagedBuilder.Append(RegexUtils.Replace(
                                                    $"({word.Replace(" ", "\\s")})(?!</a>)(?![^><]*>)", pagedContents,
                                                    $"<span style='color:#cc0000'>{word}</span>"));
                        }

                        Parser.Parse(pageInfo, contextInfo, pagedBuilder, string.Empty, false);
                        return(Ok(pagedBuilder.ToString()));
                    }
                }
                else if (StlParserUtility.IsStlElementExists(StlPageSqlContents.ElementName, stlLabelList))
                {
                    var stlElement = StlParserUtility.GetStlElement(StlPageSqlContents.ElementName, stlLabelList);

                    var stlPageSqlContents = new StlPageSqlContents(stlElement, pageInfo, contextInfo);

                    var pageCount = stlPageSqlContents.GetPageCount(out var totalNum);
                    if (totalNum == 0)
                    {
                        return(NotFound());
                    }

                    for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++)
                    {
                        if (currentPageIndex != pageIndex)
                        {
                            continue;
                        }

                        var pageHtml     = stlPageSqlContents.Parse(totalNum, currentPageIndex, pageCount, false);
                        var pagedBuilder = new StringBuilder(contentBuilder.ToString().Replace(stlElement, pageHtml));

                        StlParserManager.ReplacePageElementsInSearchPage(pagedBuilder, pageInfo, stlLabelList, ajaxDivId, pageInfo.PageChannelId, currentPageIndex, pageCount, totalNum);

                        if (isHighlight && !string.IsNullOrEmpty(word))
                        {
                            var pagedContents = pagedBuilder.ToString();
                            pagedBuilder = new StringBuilder();
                            pagedBuilder.Append(RegexUtils.Replace(
                                                    $"({word.Replace(" ", "\\s")})(?!</a>)(?![^><]*>)", pagedContents,
                                                    $"<span style='color:#cc0000'>{word}</span>"));
                        }

                        Parser.Parse(pageInfo, contextInfo, pagedBuilder, string.Empty, false);
                        return(Ok(pagedBuilder.ToString()));
                    }
                }

                Parser.Parse(pageInfo, contextInfo, contentBuilder, string.Empty, false);
                return(Ok(contentBuilder.ToString()));
            }
            catch (Exception ex)
            {
                var message = LogUtils.AddStlErrorLog(pageInfo, StlSearch.ElementName, template, ex);
                return(BadRequest(message));
            }
        }
Example #7
0
        //public int GetPageCount(out int contentNum)
        //{
        //    var pageCount = 1;
        //    contentNum = 0;//数据库中实际的内容数目
        //    if (_dataSet == null) return pageCount;

        //    contentNum = _dataSet.Tables[0].DefaultView.Count;
        //    if (_listInfo.PageNum != 0 && _listInfo.PageNum < contentNum)//需要翻页
        //    {
        //        pageCount = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(contentNum) / Convert.ToDouble(_listInfo.PageNum)));//需要生成的总页数
        //    }
        //    return pageCount;
        //}

        public string Parse(int totalNum, int currentPageIndex, int pageCount, bool isStatic)
        {
            if (isStatic)
            {
                var maxPage = _listInfo.MaxPage;
                if (maxPage == 0)
                {
                    maxPage = _pageInfo.SiteInfo.Additional.CreateStaticMaxPage;
                }
                if (maxPage > 0 && currentPageIndex + 1 > maxPage)
                {
                    return(ParseDynamic(totalNum, currentPageIndex, pageCount));
                }
            }

            var parsedContent = string.Empty;

            _contextInfo.PageItemIndex = currentPageIndex * _listInfo.PageNum;

            try
            {
                if (!string.IsNullOrEmpty(_sqlString))
                {
                    //var pageSqlString = DatabaseApi.Instance.GetPageSqlString(SqlString, ListInfo.OrderByString, totalNum, ListInfo.PageNum, currentPageIndex);
                    var pageSqlString = StlDatabaseCache.GetStlPageSqlString(_sqlString, _listInfo.OrderByString, totalNum, _listInfo.PageNum, currentPageIndex);

                    var dataSource = DataProvider.DatabaseDao.GetDataSource(pageSqlString);

                    if (_listInfo.Layout == ELayout.None)
                    {
                        var rptContents = new Repeater();

                        if (!string.IsNullOrEmpty(_listInfo.HeaderTemplate))
                        {
                            rptContents.HeaderTemplate = new SeparatorTemplate(_listInfo.HeaderTemplate);
                        }
                        if (!string.IsNullOrEmpty(_listInfo.FooterTemplate))
                        {
                            rptContents.FooterTemplate = new SeparatorTemplate(_listInfo.FooterTemplate);
                        }
                        if (!string.IsNullOrEmpty(_listInfo.SeparatorTemplate))
                        {
                            rptContents.SeparatorTemplate = new SeparatorTemplate(_listInfo.SeparatorTemplate);
                        }
                        if (!string.IsNullOrEmpty(_listInfo.AlternatingItemTemplate))
                        {
                            rptContents.AlternatingItemTemplate = new RepeaterTemplate(_listInfo.AlternatingItemTemplate, _listInfo.SelectedItems, _listInfo.SelectedValues, _listInfo.SeparatorRepeatTemplate, _listInfo.SeparatorRepeat, _pageInfo, EContextType.SqlContent, _contextInfo);
                        }

                        rptContents.ItemTemplate = new RepeaterTemplate(_listInfo.ItemTemplate, _listInfo.SelectedItems, _listInfo.SelectedValues, _listInfo.SeparatorRepeatTemplate, _listInfo.SeparatorRepeat, _pageInfo, EContextType.SqlContent, _contextInfo);

                        rptContents.DataSource = dataSource;
                        rptContents.DataBind();

                        if (rptContents.Items.Count > 0)
                        {
                            parsedContent = ControlUtils.GetControlRenderHtml(rptContents);
                        }
                    }
                    else
                    {
                        var pdlContents = new ParsedDataList();

                        //设置显示属性
                        TemplateUtility.PutListInfoToMyDataList(pdlContents, _listInfo);

                        pdlContents.ItemTemplate = new DataListTemplate(_listInfo.ItemTemplate, _listInfo.SelectedItems, _listInfo.SelectedValues, _listInfo.SeparatorRepeatTemplate, _listInfo.SeparatorRepeat, _pageInfo, EContextType.SqlContent, _contextInfo);
                        if (!string.IsNullOrEmpty(_listInfo.HeaderTemplate))
                        {
                            pdlContents.HeaderTemplate = new SeparatorTemplate(_listInfo.HeaderTemplate);
                        }
                        if (!string.IsNullOrEmpty(_listInfo.FooterTemplate))
                        {
                            pdlContents.FooterTemplate = new SeparatorTemplate(_listInfo.FooterTemplate);
                        }
                        if (!string.IsNullOrEmpty(_listInfo.SeparatorTemplate))
                        {
                            pdlContents.SeparatorTemplate = new SeparatorTemplate(_listInfo.SeparatorTemplate);
                        }
                        if (!string.IsNullOrEmpty(_listInfo.AlternatingItemTemplate))
                        {
                            pdlContents.AlternatingItemTemplate = new DataListTemplate(_listInfo.AlternatingItemTemplate, _listInfo.SelectedItems, _listInfo.SelectedValues, _listInfo.SeparatorRepeatTemplate, _listInfo.SeparatorRepeat, _pageInfo, EContextType.SqlContent, _contextInfo);
                        }

                        pdlContents.DataSource   = dataSource;
                        pdlContents.DataKeyField = ContentAttribute.Id;
                        pdlContents.DataBind();

                        if (pdlContents.Items.Count > 0)
                        {
                            parsedContent = ControlUtils.GetControlRenderHtml(pdlContents);
                        }
                    }
                }

                //if (_dataSet != null)
                //{
                //    var dataSource = new PagedDataSource { DataSource = _dataSet.Tables[0].DefaultView }; //分页类

                //    if (pageCount > 1)
                //    {
                //        dataSource.AllowPaging = true;
                //        dataSource.PageSize = _listInfo.PageNum;//每页显示的项数
                //    }
                //    else
                //    {
                //        dataSource.AllowPaging = false;
                //    }

                //    dataSource.CurrentPageIndex = currentPageIndex;//当前页的索引

                //    if (_listInfo.Layout == ELayout.None)
                //    {
                //        var rptContents = new Repeater
                //        {
                //            ItemTemplate =
                //                new RepeaterTemplate(_listInfo.ItemTemplate, _listInfo.SelectedItems,
                //                    _listInfo.SelectedValues, _listInfo.SeparatorRepeatTemplate,
                //                    _listInfo.SeparatorRepeat, _pageInfo, EContextType.SqlContent, _contextInfo)
                //        };

                //        if (!string.IsNullOrEmpty(_listInfo.HeaderTemplate))
                //        {
                //            rptContents.HeaderTemplate = new SeparatorTemplate(_listInfo.HeaderTemplate);
                //        }
                //        if (!string.IsNullOrEmpty(_listInfo.FooterTemplate))
                //        {
                //            rptContents.FooterTemplate = new SeparatorTemplate(_listInfo.FooterTemplate);
                //        }
                //        if (!string.IsNullOrEmpty(_listInfo.SeparatorTemplate))
                //        {
                //            rptContents.SeparatorTemplate = new SeparatorTemplate(_listInfo.SeparatorTemplate);
                //        }
                //        if (!string.IsNullOrEmpty(_listInfo.AlternatingItemTemplate))
                //        {
                //            rptContents.AlternatingItemTemplate = new RepeaterTemplate(_listInfo.AlternatingItemTemplate, _listInfo.SelectedItems, _listInfo.SelectedValues, _listInfo.SeparatorRepeatTemplate, _listInfo.SeparatorRepeat, _pageInfo, EContextType.SqlContent, _contextInfo);
                //        }

                //        rptContents.DataSource = dataSource;
                //        rptContents.DataBind();

                //        if (rptContents.Items.Count > 0)
                //        {
                //            parsedContent = ControlUtils.GetControlRenderHtml(rptContents);
                //        }
                //    }
                //    else
                //    {
                //        var pdlContents = new ParsedDataList();

                //        //设置显示属性
                //        TemplateUtility.PutListInfoToMyDataList(pdlContents, _listInfo);

                //        pdlContents.ItemTemplate = new DataListTemplate(_listInfo.ItemTemplate, _listInfo.SelectedItems, _listInfo.SelectedValues, _listInfo.SeparatorRepeatTemplate, _listInfo.SeparatorRepeat, _pageInfo, EContextType.SqlContent, _contextInfo);
                //        if (!string.IsNullOrEmpty(_listInfo.HeaderTemplate))
                //        {
                //            pdlContents.HeaderTemplate = new SeparatorTemplate(_listInfo.HeaderTemplate);
                //        }
                //        if (!string.IsNullOrEmpty(_listInfo.FooterTemplate))
                //        {
                //            pdlContents.FooterTemplate = new SeparatorTemplate(_listInfo.FooterTemplate);
                //        }
                //        if (!string.IsNullOrEmpty(_listInfo.SeparatorTemplate))
                //        {
                //            pdlContents.SeparatorTemplate = new SeparatorTemplate(_listInfo.SeparatorTemplate);
                //        }
                //        if (!string.IsNullOrEmpty(_listInfo.AlternatingItemTemplate))
                //        {
                //            pdlContents.AlternatingItemTemplate = new DataListTemplate(_listInfo.AlternatingItemTemplate, _listInfo.SelectedItems, _listInfo.SelectedValues, _listInfo.SeparatorRepeatTemplate, _listInfo.SeparatorRepeat, _pageInfo, EContextType.SqlContent, _contextInfo);
                //        }

                //        pdlContents.DataSource = dataSource;
                //        pdlContents.DataBind();

                //        if (pdlContents.Items.Count > 0)
                //        {
                //            parsedContent = ControlUtils.GetControlRenderHtml(pdlContents);
                //        }
                //    }
                //}
            }
            catch (Exception ex)
            {
                parsedContent = LogUtils.AddStlErrorLog(_pageInfo, ElementName, _stlPageSqlContentsElement, ex);
            }

            //还原翻页为0,使得其他列表能够正确解析ItemIndex
            _contextInfo.PageItemIndex = 0;

            return(parsedContent);
        }
Example #8
0
        public static void Parse(PageInfo pageInfo, ContextInfo contextInfo, StringBuilder contentBuilder, string filePath, bool isDynamic)
        {
            foreach (var service in PluginManager.Services)
            {
                try
                {
                    service.OnBeforeStlParse(new ParseEventArgs
                                             (
                                                 pageInfo.SiteId,
                                                 pageInfo.PageChannelId,
                                                 pageInfo.PageContentId,
                                                 contextInfo.ContentInfo,
                                                 pageInfo.TemplateInfo.TemplateType,
                                                 pageInfo.TemplateInfo.Id,
                                                 filePath,
                                                 pageInfo.HeadCodes,
                                                 pageInfo.BodyCodes,
                                                 pageInfo.FootCodes,
                                                 contentBuilder
                                             ));
                }
                catch (Exception ex)
                {
                    LogUtils.AddStlErrorLog(pageInfo, service.PluginId, nameof(service.OnBeforeStlParse), ex);
                }
            }

            if (contentBuilder.Length > 0)
            {
                StlParserManager.ParseTemplateContent(contentBuilder, pageInfo, contextInfo);
            }

            foreach (var service in PluginManager.Services)
            {
                try
                {
                    service.OnAfterStlParse(new ParseEventArgs(pageInfo.SiteId, pageInfo.PageChannelId, pageInfo.PageContentId, contextInfo.ContentInfo, pageInfo.TemplateInfo.TemplateType, pageInfo.TemplateInfo.Id, filePath, pageInfo.HeadCodes, pageInfo.BodyCodes, pageInfo.FootCodes, contentBuilder));
                }
                catch (Exception ex)
                {
                    LogUtils.AddStlErrorLog(pageInfo, service.PluginId, nameof(service.OnAfterStlParse), ex);
                }
            }

            if (EFileSystemTypeUtils.IsHtml(PathUtils.GetExtension(filePath)))
            {
                if (isDynamic)
                {
                    var    pageUrl        = PageUtils.AddProtocolToUrl(PageUtils.ParseNavigationUrl($"~/{PathUtils.GetPathDifference(WebConfigUtils.PhysicalApplicationPath, filePath)}"));
                    string templateString = $@"
<base href=""{pageUrl}"" />";
                    StringUtils.InsertAfter(new[] { "<head>", "<HEAD>" }, contentBuilder, templateString);
                }

                if (pageInfo.SiteInfo.Additional.IsCreateBrowserNoCache)
                {
                    const string templateString = @"
<META HTTP-EQUIV=""Pragma"" CONTENT=""no-cache"">
<META HTTP-EQUIV=""Expires"" CONTENT=""-1"">";
                    StringUtils.InsertAfter(new[] { "<head>", "<HEAD>" }, contentBuilder, templateString);
                }

                if (pageInfo.SiteInfo.Additional.IsCreateIe8Compatible)
                {
                    const string templateString = @"
<META HTTP-EQUIV=""x-ua-compatible"" CONTENT=""ie=7"" />";
                    StringUtils.InsertAfter(new[] { "<head>", "<HEAD>" }, contentBuilder, templateString);
                }

                if (pageInfo.SiteInfo.Additional.IsCreateJsIgnoreError)
                {
                    const string templateString = @"
<script type=""text/javascript"">window.onerror=function(){return true;}</script>";
                    StringUtils.InsertAfter(new[] { "<head>", "<HEAD>" }, contentBuilder, templateString);
                }

                var isShowPageInfo = pageInfo.SiteInfo.Additional.IsCreateShowPageInfo;

                if (!pageInfo.IsLocal)
                {
                    if (pageInfo.SiteInfo.Additional.IsCreateDoubleClick)
                    {
                        var fileTemplateId = 0;
                        if (pageInfo.TemplateInfo.TemplateType == TemplateType.FileTemplate)
                        {
                            fileTemplateId = pageInfo.TemplateInfo.Id;
                        }

                        var apiUrl  = pageInfo.ApiUrl;
                        var ajaxUrl = ApiRouteActionsTrigger.GetUrl(apiUrl, pageInfo.SiteId, contextInfo.ChannelId,
                                                                    contextInfo.ContentId, fileTemplateId, true);
                        if (!pageInfo.FootCodes.ContainsKey("CreateDoubleClick"))
                        {
                            pageInfo.FootCodes.Add("CreateDoubleClick", $@"
<script type=""text/javascript"" language=""javascript"">document.ondblclick=function(x){{location.href = '{ajaxUrl}&returnUrl=' + encodeURIComponent(location.search);}}</script>");
                        }
                    }
                }
                else
                {
                    isShowPageInfo = true;
                }

                if (isShowPageInfo)
                {
                    contentBuilder.Append($@"
<!-- {pageInfo.TemplateInfo.RelatedFileName}({TemplateTypeUtils.GetText(pageInfo.TemplateInfo.TemplateType)}) -->");
                }

                var headCodesHtml = pageInfo.HeadCodesHtml;
                if (!string.IsNullOrEmpty(headCodesHtml))
                {
                    if (contentBuilder.ToString().IndexOf("</head>", StringComparison.Ordinal) != -1 || contentBuilder.ToString().IndexOf("</HEAD>", StringComparison.Ordinal) != -1)
                    {
                        StringUtils.InsertBefore(new[] { "</head>", "</HEAD>" }, contentBuilder, headCodesHtml);
                    }
                    else
                    {
                        contentBuilder.Insert(0, headCodesHtml);
                    }
                }

                var bodyCodesHtml = pageInfo.BodyCodesHtml;
                if (!string.IsNullOrEmpty(bodyCodesHtml))
                {
                    if (contentBuilder.ToString().IndexOf("<body", StringComparison.Ordinal) != -1 || contentBuilder.ToString().IndexOf("<BODY", StringComparison.Ordinal) != -1)
                    {
                        var index = contentBuilder.ToString().IndexOf("<body", StringComparison.Ordinal);
                        if (index == -1)
                        {
                            index = contentBuilder.ToString().IndexOf("<BODY", StringComparison.Ordinal);
                        }
                        index = contentBuilder.ToString().IndexOf(">", index, StringComparison.Ordinal);
                        contentBuilder.Insert(index + 1, Constants.ReturnAndNewline + bodyCodesHtml + Constants.ReturnAndNewline);
                    }
                    else
                    {
                        contentBuilder.Insert(0, bodyCodesHtml);
                    }
                }

                var footCodesHtml = pageInfo.FootCodesHtml;
                if (!string.IsNullOrEmpty(footCodesHtml))
                {
                    contentBuilder.Append(footCodesHtml + Constants.ReturnAndNewline);
                }
            }
        }
Example #9
0
        public string Parse(int totalNum, int currentPageIndex, int pageCount, bool isStatic)
        {
            if (isStatic)
            {
                var maxPage = ListInfo.MaxPage;
                if (maxPage == 0)
                {
                    maxPage = _pageInfo.SiteInfo.Additional.CreateStaticMaxPage;
                }
                if (maxPage > 0 && currentPageIndex + 1 > maxPage)
                {
                    return(ParseDynamic(totalNum, currentPageIndex, pageCount));
                }
            }

            var parsedContent = string.Empty;

            _contextInfo.PageItemIndex = currentPageIndex * ListInfo.PageNum;

            try
            {
                if (!string.IsNullOrEmpty(SqlString))
                {
                    //var pageSqlString = DataProvider.DatabaseDao.GetPageSqlString(SqlString, ListInfo.OrderByString, totalNum, ListInfo.PageNum, currentPageIndex);
                    var pageSqlString = StlDatabaseCache.GetStlPageSqlString(SqlString, ListInfo.OrderByString, totalNum, ListInfo.PageNum, currentPageIndex);

                    var datasource = DataProvider.DatabaseDao.GetDataSource(pageSqlString);

                    if (ListInfo.Layout == ELayout.None)
                    {
                        var rptContents = new Repeater();

                        if (!string.IsNullOrEmpty(ListInfo.HeaderTemplate))
                        {
                            rptContents.HeaderTemplate = new SeparatorTemplate(ListInfo.HeaderTemplate);
                        }
                        if (!string.IsNullOrEmpty(ListInfo.FooterTemplate))
                        {
                            rptContents.FooterTemplate = new SeparatorTemplate(ListInfo.FooterTemplate);
                        }
                        if (!string.IsNullOrEmpty(ListInfo.SeparatorTemplate))
                        {
                            rptContents.SeparatorTemplate = new SeparatorTemplate(ListInfo.SeparatorTemplate);
                        }
                        if (!string.IsNullOrEmpty(ListInfo.AlternatingItemTemplate))
                        {
                            rptContents.AlternatingItemTemplate = new RepeaterTemplate(ListInfo.AlternatingItemTemplate, ListInfo.SelectedItems, ListInfo.SelectedValues, ListInfo.SeparatorRepeatTemplate, ListInfo.SeparatorRepeat, _pageInfo, EContextType.Content, _contextInfo);
                        }

                        rptContents.ItemTemplate = new RepeaterTemplate(ListInfo.ItemTemplate, ListInfo.SelectedItems, ListInfo.SelectedValues, ListInfo.SeparatorRepeatTemplate, ListInfo.SeparatorRepeat, _pageInfo, EContextType.Content, _contextInfo);

                        rptContents.DataSource = datasource;
                        rptContents.DataBind();

                        if (rptContents.Items.Count > 0)
                        {
                            parsedContent = ControlUtils.GetControlRenderHtml(rptContents);
                        }
                    }
                    else
                    {
                        var pdlContents = new ParsedDataList();

                        //设置显示属性
                        TemplateUtility.PutListInfoToMyDataList(pdlContents, ListInfo);

                        pdlContents.ItemTemplate = new DataListTemplate(ListInfo.ItemTemplate, ListInfo.SelectedItems, ListInfo.SelectedValues, ListInfo.SeparatorRepeatTemplate, ListInfo.SeparatorRepeat, _pageInfo, EContextType.Content, _contextInfo);
                        if (!string.IsNullOrEmpty(ListInfo.HeaderTemplate))
                        {
                            pdlContents.HeaderTemplate = new SeparatorTemplate(ListInfo.HeaderTemplate);
                        }
                        if (!string.IsNullOrEmpty(ListInfo.FooterTemplate))
                        {
                            pdlContents.FooterTemplate = new SeparatorTemplate(ListInfo.FooterTemplate);
                        }
                        if (!string.IsNullOrEmpty(ListInfo.SeparatorTemplate))
                        {
                            pdlContents.SeparatorTemplate = new SeparatorTemplate(ListInfo.SeparatorTemplate);
                        }
                        if (!string.IsNullOrEmpty(ListInfo.AlternatingItemTemplate))
                        {
                            pdlContents.AlternatingItemTemplate = new DataListTemplate(ListInfo.AlternatingItemTemplate, ListInfo.SelectedItems, ListInfo.SelectedValues, ListInfo.SeparatorRepeatTemplate, ListInfo.SeparatorRepeat, _pageInfo, EContextType.Content, _contextInfo);
                        }

                        pdlContents.DataSource   = datasource;
                        pdlContents.DataKeyField = ContentAttribute.Id;
                        pdlContents.DataBind();

                        if (pdlContents.Items.Count > 0)
                        {
                            parsedContent = ControlUtils.GetControlRenderHtml(pdlContents);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                parsedContent = LogUtils.AddStlErrorLog(_pageInfo, ElementName, _stlPageContentsElement, ex);
            }

            //还原翻页为0,使得其他列表能够正确解析ItemIndex
            _contextInfo.PageItemIndex = 0;
            return(parsedContent);
        }
Example #10
0
        public string Parse(int currentPageIndex, int pageCount)
        {
            var parsedContent = string.Empty;

            _contextInfo.PageItemIndex = currentPageIndex * DisplayInfo.PageNum;

            try
            {
                if (_dataSet != null)
                {
                    var objPage = new PagedDataSource {
                        DataSource = _dataSet.Tables[0].DefaultView
                    };                                                                                 //分页类

                    if (pageCount > 1)
                    {
                        objPage.AllowPaging = true;
                        objPage.PageSize    = DisplayInfo.PageNum;//每页显示的项数
                    }
                    else
                    {
                        objPage.AllowPaging = false;
                    }

                    objPage.CurrentPageIndex = currentPageIndex;//当前页的索引


                    if (DisplayInfo.Layout == ELayout.None)
                    {
                        var rptContents = new Repeater
                        {
                            ItemTemplate =
                                new RepeaterTemplate(DisplayInfo.ItemTemplate, DisplayInfo.SelectedItems,
                                                     DisplayInfo.SelectedValues, DisplayInfo.SeparatorRepeatTemplate,
                                                     DisplayInfo.SeparatorRepeat, _pageInfo, EContextType.Channel, _contextInfo)
                        };

                        if (!string.IsNullOrEmpty(DisplayInfo.HeaderTemplate))
                        {
                            rptContents.HeaderTemplate = new SeparatorTemplate(DisplayInfo.HeaderTemplate);
                        }
                        if (!string.IsNullOrEmpty(DisplayInfo.FooterTemplate))
                        {
                            rptContents.FooterTemplate = new SeparatorTemplate(DisplayInfo.FooterTemplate);
                        }
                        if (!string.IsNullOrEmpty(DisplayInfo.SeparatorTemplate))
                        {
                            rptContents.SeparatorTemplate = new SeparatorTemplate(DisplayInfo.SeparatorTemplate);
                        }
                        if (!string.IsNullOrEmpty(DisplayInfo.AlternatingItemTemplate))
                        {
                            rptContents.AlternatingItemTemplate = new RepeaterTemplate(DisplayInfo.AlternatingItemTemplate, DisplayInfo.SelectedItems, DisplayInfo.SelectedValues, DisplayInfo.SeparatorRepeatTemplate, DisplayInfo.SeparatorRepeat, _pageInfo, EContextType.Channel, _contextInfo);
                        }

                        rptContents.DataSource = objPage;
                        rptContents.DataBind();

                        if (rptContents.Items.Count > 0)
                        {
                            parsedContent = ControlUtils.GetControlRenderHtml(rptContents);
                        }
                    }
                    else
                    {
                        var pdlContents = new ParsedDataList();

                        //设置显示属性
                        TemplateUtility.PutListInfoToMyDataList(pdlContents, DisplayInfo);

                        //设置列表模板
                        pdlContents.ItemTemplate = new DataListTemplate(DisplayInfo.ItemTemplate, DisplayInfo.SelectedItems, DisplayInfo.SelectedValues, DisplayInfo.SeparatorRepeatTemplate, DisplayInfo.SeparatorRepeat, _pageInfo, EContextType.Channel, _contextInfo);
                        if (!string.IsNullOrEmpty(DisplayInfo.HeaderTemplate))
                        {
                            pdlContents.HeaderTemplate = new SeparatorTemplate(DisplayInfo.HeaderTemplate);
                        }
                        if (!string.IsNullOrEmpty(DisplayInfo.FooterTemplate))
                        {
                            pdlContents.FooterTemplate = new SeparatorTemplate(DisplayInfo.FooterTemplate);
                        }
                        if (!string.IsNullOrEmpty(DisplayInfo.SeparatorTemplate))
                        {
                            pdlContents.SeparatorTemplate = new SeparatorTemplate(DisplayInfo.SeparatorTemplate);
                        }
                        if (!string.IsNullOrEmpty(DisplayInfo.AlternatingItemTemplate))
                        {
                            pdlContents.AlternatingItemTemplate = new DataListTemplate(DisplayInfo.AlternatingItemTemplate, DisplayInfo.SelectedItems, DisplayInfo.SelectedValues, DisplayInfo.SeparatorRepeatTemplate, DisplayInfo.SeparatorRepeat, _pageInfo, EContextType.Channel, _contextInfo);
                        }

                        pdlContents.DataSource   = objPage;
                        pdlContents.DataKeyField = ChannelAttribute.Id;
                        pdlContents.DataBind();

                        if (pdlContents.Items.Count > 0)
                        {
                            parsedContent = ControlUtils.GetControlRenderHtml(pdlContents);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                parsedContent = LogUtils.AddStlErrorLog(_pageInfo, ElementName, _stlPageChannelsElement, ex);
            }

            //还原翻页为0,使得其他列表能够正确解析ItemIndex
            _contextInfo.PageItemIndex = 0;

            return(parsedContent);
        }