Esempio n. 1
0
        public async Task <string> GetCurrentUrlAsync()
        {
            var contextInfo = ParseManager.ContextInfo;
            var pageInfo    = ParseManager.PageInfo;
            var contentInfo = await ParseManager.GetContentAsync();

            return(await StlParserUtility.GetStlCurrentUrlAsync(ParseManager, pageInfo.Site, contextInfo.ChannelId, contextInfo.ContentId, contentInfo, pageInfo.Template.TemplateType, pageInfo.Template.Id, pageInfo.IsLocal));
        }
Esempio n. 2
0
        internal static async Task <string> ParseAsync(string stlEntity, IParseManager parseManager)
        {
            var databaseManager = parseManager.DatabaseManager;
            var pageInfo        = parseManager.PageInfo;
            var contextInfo     = parseManager.ContextInfo;

            var parsedContent = string.Empty;

            try
            {
                var entityName    = StlParserUtility.GetNameFromEntity(stlEntity);
                var attributeName = entityName.Substring(5, entityName.Length - 6);

                if (StringUtils.EqualsIgnoreCase(PoweredBy, attributeName))//支持信息
                {
                    parsedContent = @$ "Powered by <a href=" "{CloudUtils.Www.Host}" " target=" "_blank" ">SS CMS</a>";
                }
                else if (StringUtils.EqualsIgnoreCase(RootUrl, attributeName))//系统根目录地址
                {
                    parsedContent = parseManager.PathManager.ParseUrl("~");
                    if (!string.IsNullOrEmpty(parsedContent))
                    {
                        parsedContent = parsedContent.TrimEnd('/');
                    }
                }
                else if (StringUtils.EqualsIgnoreCase(ApiUrl, attributeName))//API地址
                {
                    parsedContent = parseManager.PathManager.GetRootUrl();
                }
                else if (StringUtils.EqualsIgnoreCase(SiteId, attributeName))//ID
                {
                    parsedContent = pageInfo.SiteId.ToString();
                }
                else if (StringUtils.EqualsIgnoreCase(SiteName, attributeName))//名称
                {
                    parsedContent = pageInfo.Site.SiteName;
                }
                else if (StringUtils.EqualsIgnoreCase(SiteUrl, attributeName))//域名地址
                {
                    parsedContent = (await parseManager.PathManager.GetSiteUrlAsync(pageInfo.Site, pageInfo.IsLocal)).TrimEnd('/');
                }
                else if (StringUtils.EqualsIgnoreCase(SiteDir, attributeName))//文件夹
                {
                    parsedContent = pageInfo.Site.SiteDir;
                }
                else if (StringUtils.EqualsIgnoreCase(CurrentUrl, attributeName))//当前页地址
                {
                    var contentInfo = await parseManager.GetContentAsync();

                    parsedContent = await StlParserUtility.GetStlCurrentUrlAsync(parseManager, pageInfo.Site, contextInfo.ChannelId, contextInfo.ContentId, contentInfo, pageInfo.Template.TemplateType, pageInfo.Template.Id, pageInfo.IsLocal);
                }
                else if (StringUtils.EqualsIgnoreCase(ChannelUrl, attributeName))//栏目页地址
                {
                    parsedContent = await parseManager.PathManager.GetChannelUrlAsync(pageInfo.Site, await databaseManager.ChannelRepository.GetAsync(contextInfo.ChannelId), pageInfo.IsLocal);
                }
                else if (StringUtils.EqualsIgnoreCase(HomeUrl, attributeName))//用户中心地址
                {
                    parsedContent = parseManager.PathManager.GetHomeUrl(string.Empty).TrimEnd('/');
                }
                else if (StringUtils.EqualsIgnoreCase(LoginUrl, attributeName))
                {
                    var contentInfo = await parseManager.GetContentAsync();

                    var returnUrl = await StlParserUtility.GetStlCurrentUrlAsync(parseManager, pageInfo.Site, contextInfo.ChannelId, contextInfo.ContentId, contentInfo, pageInfo.Template.TemplateType, pageInfo.Template.Id, pageInfo.IsLocal);

                    parsedContent = parseManager.PathManager.GetHomeUrl($"pages/login.html?returnUrl={PageUtils.UrlEncode(returnUrl)}");
                }
                else if (StringUtils.EqualsIgnoreCase(LogoutUrl, attributeName))
                {
                    var contentInfo = await parseManager.GetContentAsync();

                    var returnUrl = await StlParserUtility.GetStlCurrentUrlAsync(parseManager, pageInfo.Site, contextInfo.ChannelId, contextInfo.ContentId, contentInfo, pageInfo.Template.TemplateType, pageInfo.Template.Id, pageInfo.IsLocal);

                    parsedContent = parseManager.PathManager.GetHomeUrl($"pages/logout.html?returnUrl={PageUtils.UrlEncode(returnUrl)}");
                }
                else if (StringUtils.EqualsIgnoreCase(RegisterUrl, attributeName))
                {
                    var contentInfo = await parseManager.GetContentAsync();

                    var returnUrl = await StlParserUtility.GetStlCurrentUrlAsync(parseManager, pageInfo.Site, contextInfo.ChannelId, contextInfo.ContentId, contentInfo, pageInfo.Template.TemplateType, pageInfo.Template.Id, pageInfo.IsLocal);

                    parsedContent = parseManager.PathManager.GetHomeUrl($"pages/register.html?returnUrl={PageUtils.UrlEncode(returnUrl)}");
                }
                else if (StringUtils.StartsWithIgnoreCase(attributeName, "TableFor"))//
                {
                    if (StringUtils.EqualsIgnoreCase(attributeName, "TableForContent"))
                    {
                        parsedContent = pageInfo.Site.TableName;
                    }
                }
                else if (StringUtils.StartsWithIgnoreCase(attributeName, "Site"))//
                {
                    parsedContent = pageInfo.Site.Get <string>(attributeName.Substring(4));
                }
                else if (pageInfo.Parameters != null && pageInfo.Parameters.ContainsKey(attributeName))
                {
                    pageInfo.Parameters.TryGetValue(attributeName, out parsedContent);
                }
                else
                {
                    if (pageInfo.Site.ContainsKey(attributeName))
                    {
                        parsedContent = pageInfo.Site.Get <string>(attributeName);

                        if (!string.IsNullOrEmpty(parsedContent))
                        {
                            var styleInfo = await databaseManager.TableStyleRepository.GetTableStyleAsync(databaseManager.SiteRepository.TableName, attributeName, databaseManager.TableStyleRepository.GetRelatedIdentities(pageInfo.SiteId));

                            if (styleInfo.Id > 0)
                            {
                                var inputParser = new InputParserManager(parseManager.PathManager);

                                parsedContent = InputTypeUtils.EqualsAny(styleInfo.InputType, InputType.Image,
                                                                         InputType.File)
                                    ? await parseManager.PathManager.ParseSiteUrlAsync(pageInfo.Site, parsedContent,
                                                                                       pageInfo.IsLocal)
                                    : await inputParser.GetContentByTableStyleAsync(parsedContent, string.Empty, pageInfo.Site, styleInfo, string.Empty, null, string.Empty,
                                                                                    true);
                            }
                            else
                            { // 如果字段已经被删除或不再显示了,则此字段的值为空。有时虚拟字段值不会清空
                                parsedContent = string.Empty;
                            }
                        }
                    }
                }
            }
            catch
            {
                // ignored
            }

            return(parsedContent);
        }
Esempio n. 3
0
        private static async Task <object> ParseImplAsync(IParseManager parseManager, string type, string formatString, int startIndex, int length, int wordNum, string ellipsis, string replace, string to, bool isClearTags, bool isReturnToBr, bool isLower, bool isUpper)
        {
            var pageInfo    = parseManager.PageInfo;
            var contextInfo = parseManager.ContextInfo;

            if (string.IsNullOrEmpty(type))
            {
                return(string.Empty);
            }

            var parsedContent = string.Empty;

            if (contextInfo.ContextType == ParseType.Each)
            {
                parsedContent = contextInfo.ItemContainer.EachItem.Value as string;
                return(parsedContent);
            }

            if (StringUtils.EqualsIgnoreCase(type, TypeDate))
            {
                if (!pageInfo.BodyCodes.ContainsKey("datestring.js"))
                {
                    var jsUrl = parseManager.PathManager.GetSiteFilesUrl(Resources.DateString.Js);

                    pageInfo.BodyCodes.Add("datestring.js", $@"<script charset=""{Resources.DateString.Charset}"" src=""{jsUrl}"" type=""text/javascript""></script>");
                }

                parsedContent = @"<script language=""javascript"" type=""text/javascript"">RunGLNL(false);</script>";
            }
            else if (StringUtils.EqualsIgnoreCase(type, TypeDateOfTraditional))
            {
                if (!pageInfo.BodyCodes.ContainsKey("datestring"))
                {
                    var jsUrl = parseManager.PathManager.GetSiteFilesUrl(Resources.DateString.Js);

                    pageInfo.BodyCodes.Add("datestring", $@"<script charset=""{Resources.DateString.Charset}"" src=""{jsUrl}"" type=""text/javascript""></script>");
                }

                parsedContent = @"<script language=""javascript"" type=""text/javascript"">RunGLNL(true);</script>";
            }
            else if (StringUtils.EqualsIgnoreCase(TypeRootUrl, type))//系统根目录地址
            {
                parsedContent = parseManager.PathManager.ParseUrl("~");
                if (!string.IsNullOrEmpty(parsedContent))
                {
                    parsedContent = parsedContent.TrimEnd('/');
                }
            }
            else if (StringUtils.EqualsIgnoreCase(TypeApiUrl, type))//API地址
            {
                parsedContent = parseManager.PathManager.GetRootUrl();
            }
            else if (StringUtils.EqualsIgnoreCase(TypeSiteId, type))//ID
            {
                parsedContent = pageInfo.SiteId.ToString();
            }
            else if (StringUtils.EqualsIgnoreCase(TypeSiteName, type))//名称
            {
                parsedContent = pageInfo.Site.SiteName;
            }
            else if (StringUtils.EqualsIgnoreCase(TypeSiteUrl, type))//域名地址
            {
                parsedContent = (await parseManager.PathManager.GetSiteUrlAsync(pageInfo.Site, pageInfo.IsLocal)).TrimEnd('/');
            }
            else if (StringUtils.EqualsIgnoreCase(TypeSiteDir, type))//文件夹
            {
                parsedContent = pageInfo.Site.SiteDir;
            }
            else if (StringUtils.EqualsIgnoreCase(TypeCurrentUrl, type))//当前页地址
            {
                var contentInfo = await parseManager.GetContentAsync();

                parsedContent = await StlParserUtility.GetStlCurrentUrlAsync(parseManager, pageInfo.Site, contextInfo.ChannelId, contextInfo.ContentId, contentInfo, pageInfo.Template.TemplateType, pageInfo.Template.Id, pageInfo.IsLocal);
            }
            else if (StringUtils.EqualsIgnoreCase(TypeChannelUrl, type))//栏目页地址
            {
                parsedContent = await parseManager.PathManager.GetChannelUrlAsync(pageInfo.Site, await parseManager.DatabaseManager.ChannelRepository.GetAsync(contextInfo.ChannelId), pageInfo.IsLocal);
            }
            else if (StringUtils.EqualsIgnoreCase(TypeHomeUrl, type))//用户中心地址
            {
                parsedContent = parseManager.PathManager.GetHomeUrl(string.Empty).TrimEnd('/');
            }
            else if (StringUtils.EqualsIgnoreCase(TypeLoginUrl, type))
            {
                var contentInfo = await parseManager.GetContentAsync();

                var returnUrl = await StlParserUtility.GetStlCurrentUrlAsync(parseManager, pageInfo.Site, contextInfo.ChannelId, contextInfo.ContentId, contentInfo, pageInfo.Template.TemplateType, pageInfo.Template.Id, pageInfo.IsLocal);

                parsedContent = parseManager.PathManager.GetHomeUrl($"pages/login.html?returnUrl={PageUtils.UrlEncode(returnUrl)}");
            }
            else if (StringUtils.EqualsIgnoreCase(TypeLogoutUrl, type))
            {
                var contentInfo = await parseManager.GetContentAsync();

                var returnUrl = await StlParserUtility.GetStlCurrentUrlAsync(parseManager, pageInfo.Site, contextInfo.ChannelId, contextInfo.ContentId, contentInfo, pageInfo.Template.TemplateType, pageInfo.Template.Id, pageInfo.IsLocal);

                parsedContent = parseManager.PathManager.GetHomeUrl($"pages/logout.html?returnUrl={PageUtils.UrlEncode(returnUrl)}");
            }
            else if (StringUtils.EqualsIgnoreCase(TypeRegisterUrl, type))
            {
                var contentInfo = await parseManager.GetContentAsync();

                var returnUrl = await StlParserUtility.GetStlCurrentUrlAsync(parseManager, pageInfo.Site, contextInfo.ChannelId, contextInfo.ContentId, contentInfo, pageInfo.Template.TemplateType, pageInfo.Template.Id, pageInfo.IsLocal);

                parsedContent = parseManager.PathManager.GetHomeUrl($"pages/register.html?returnUrl={PageUtils.UrlEncode(returnUrl)}");
            }
            else if (StringUtils.StartsWithIgnoreCase(type, "TableFor"))//
            {
                if (StringUtils.EqualsIgnoreCase(type, "TableForContent"))
                {
                    parsedContent = pageInfo.Site.TableName;
                }
            }
            else if (StringUtils.StartsWithIgnoreCase(type, "Site"))//
            {
                parsedContent = pageInfo.Site.Get <string>(type.Substring(4));
            }
            else if (pageInfo.Parameters != null && pageInfo.Parameters.ContainsKey(type))
            {
                pageInfo.Parameters.TryGetValue(type, out parsedContent);
                parsedContent = InputTypeUtils.ParseString(InputType.Text, parsedContent, replace, to, startIndex, length, wordNum, ellipsis, isClearTags, isReturnToBr, isLower, isUpper, formatString);
            }
            else
            {
                return(await StlSite.ParseAsync(parseManager));
            }
            return(parsedContent);
        }