private static string ParseImpl(PageInfo pageInfo, ContextInfo contextInfo, XmlNode node, NameValueCollection attributes, string type, string returnUrl) { var stlAnchor = new HtmlAnchor(); foreach (string attributeName in attributes.Keys) { stlAnchor.Attributes.Add(attributeName, attributes[attributeName]); } var url = PageUtils.UnclickedUrl; var onclick = string.Empty; var innerBuilder = new StringBuilder(node.InnerXml); StlParserManager.ParseInnerContent(innerBuilder, pageInfo, contextInfo); stlAnchor.InnerHtml = innerBuilder.ToString(); //计算动作开始 if (!string.IsNullOrEmpty(type)) { if (StringUtils.EqualsIgnoreCase(type, TypeLogin)) { if (string.IsNullOrEmpty(returnUrl)) { returnUrl = StlUtility.GetStlCurrentUrl(pageInfo, contextInfo.ChannelId, contextInfo.ContentId, contextInfo.ContentInfo); } url = HomeUtils.GetLoginUrl(pageInfo.HomeUrl, returnUrl); } else if (StringUtils.EqualsIgnoreCase(type, TypeRegister)) { if (string.IsNullOrEmpty(returnUrl)) { returnUrl = StlUtility.GetStlCurrentUrl(pageInfo, contextInfo.ChannelId, contextInfo.ContentId, contextInfo.ContentInfo); } url = HomeUtils.GetRegisterUrl(pageInfo.HomeUrl, returnUrl); } else if (StringUtils.EqualsIgnoreCase(type, TypeLogout)) { if (string.IsNullOrEmpty(returnUrl)) { returnUrl = StlUtility.GetStlCurrentUrl(pageInfo, contextInfo.ChannelId, contextInfo.ContentId, contextInfo.ContentInfo); } url = HomeUtils.GetLogoutUrl(pageInfo.HomeUrl, returnUrl); } else if (StringUtils.EqualsIgnoreCase(type, TypeAddFavorite)) { pageInfo.SetPageScripts(TypeAddFavorite, @" <script type=""text/javascript""> function AddFavorite(){ if (document.all) { window.external.addFavorite(window.location.href, document.title); } else if (window.sidebar) { window.sidebar.addPanel(document.title, window.location.href, """"); } } </script> ", true); stlAnchor.Attributes["onclick"] = "AddFavorite();"; } else if (StringUtils.EqualsIgnoreCase(type, TypeSetHomePage)) { url = pageInfo.PublishmentSystemInfo.PublishmentSystemUrl; pageInfo.AddPageEndScriptsIfNotExists(TypeAddFavorite, $@" <script type=""text/javascript""> function SetHomepage(){{ if (document.all) {{ document.body.style.behavior = 'url(#default#homepage)'; document.body.setHomePage(""{url}""); }} else if (window.sidebar) {{ if (window.netscape) {{ try {{ netscape.security.PrivilegeManager.enablePrivilege(""UniversalXPConnect""); }} catch(e) {{ alert(""该操作被浏览器拒绝,如果想启用该功能,请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true""); }} }} var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch); prefs.setCharPref('browser.startup.homepage', ""{url}""); }} }} </script> "); stlAnchor.Attributes["onclick"] = "SetHomepage();"; } else if (StringUtils.EqualsIgnoreCase(type, TypeTranslate)) { pageInfo.AddPageScriptsIfNotExists(PageInfo.JsAhTranslate); var msgToTraditionalChinese = "繁體"; var msgToSimplifiedChinese = "简体"; if (!string.IsNullOrEmpty(stlAnchor.InnerHtml)) { if (stlAnchor.InnerHtml.IndexOf(",", StringComparison.Ordinal) != -1) { msgToTraditionalChinese = stlAnchor.InnerHtml.Substring(0, stlAnchor.InnerHtml.IndexOf(",", StringComparison.Ordinal)); msgToSimplifiedChinese = stlAnchor.InnerHtml.Substring(stlAnchor.InnerHtml.IndexOf(",", StringComparison.Ordinal) + 1); } else { msgToTraditionalChinese = stlAnchor.InnerHtml; } } stlAnchor.InnerHtml = msgToTraditionalChinese; if (string.IsNullOrEmpty(stlAnchor.ID)) { stlAnchor.ID = "translateLink"; } pageInfo.SetPageEndScripts(TypeTranslate, $@" <script type=""text/javascript""> var defaultEncoding = 0; var translateDelay = 0; var cookieDomain = ""/""; var msgToTraditionalChinese = ""{msgToTraditionalChinese}""; var msgToSimplifiedChinese = ""{msgToSimplifiedChinese}""; var translateButtonId = ""{stlAnchor.ClientID}""; translateInitilization(); </script> "); } else if (StringUtils.EqualsIgnoreCase(type, TypeClose)) { url = "javascript:window.close()"; } } //计算动作结束 stlAnchor.HRef = url; if (!string.IsNullOrEmpty(onclick)) { stlAnchor.Attributes.Add("onclick", onclick); } return(ControlUtils.GetControlRenderHtml(stlAnchor)); }
internal static string Parse(string stlEntity, PageInfo pageInfo, ContextInfo 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=""http://www.siteserver.cn"" target=""_blank"">SiteServer CMS</a>"; } else if (StringUtils.EqualsIgnoreCase(RootUrl, attributeName))//系统根目录地址 { parsedContent = PageUtils.ParseConfigRootUrl("~"); if (!string.IsNullOrEmpty(parsedContent)) { parsedContent = parsedContent.TrimEnd('/'); } } else if (StringUtils.EqualsIgnoreCase(ApiUrl, attributeName))//API地址 { parsedContent = pageInfo.ApiUrl.TrimEnd('/'); } else if (StringUtils.EqualsIgnoreCase(SiteId, attributeName))//ID { parsedContent = pageInfo.PublishmentSystemId.ToString(); } else if (StringUtils.EqualsIgnoreCase(SiteName, attributeName))//名称 { parsedContent = pageInfo.PublishmentSystemInfo.PublishmentSystemName; } else if (StringUtils.EqualsIgnoreCase(SiteUrl, attributeName))//域名地址 { if (!string.IsNullOrEmpty(pageInfo.PublishmentSystemInfo.PublishmentSystemUrl)) { parsedContent = pageInfo.PublishmentSystemInfo.PublishmentSystemUrl.TrimEnd('/'); } } else if (StringUtils.EqualsIgnoreCase(SiteDir, attributeName))//文件夹 { parsedContent = pageInfo.PublishmentSystemInfo.PublishmentSystemDir; } else if (StringUtils.EqualsIgnoreCase(CurrentUrl, attributeName))//当前页地址 { parsedContent = StlUtility.GetStlCurrentUrl(pageInfo, contextInfo.ChannelId, contextInfo.ContentId, contextInfo.ContentInfo); } else if (StringUtils.EqualsIgnoreCase(ChannelUrl, attributeName))//栏目页地址 { parsedContent = PageUtility.GetChannelUrl(pageInfo.PublishmentSystemInfo, NodeManager.GetNodeInfo(pageInfo.PublishmentSystemId, contextInfo.ChannelId)); } else if (StringUtils.EqualsIgnoreCase(HomeUrl, attributeName))//用户中心地址 { parsedContent = pageInfo.HomeUrl.TrimEnd('/'); } else if (StringUtils.EqualsIgnoreCase(attributeName, LoginUrl)) { var returnUrl = StlUtility.GetStlCurrentUrl(pageInfo, contextInfo.ChannelId, contextInfo.ContentId, contextInfo.ContentInfo); parsedContent = HomeUtils.GetLoginUrl(pageInfo.HomeUrl, returnUrl); } else if (StringUtils.EqualsIgnoreCase(attributeName, LogoutUrl)) { var returnUrl = StlUtility.GetStlCurrentUrl(pageInfo, contextInfo.ChannelId, contextInfo.ContentId, contextInfo.ContentInfo); parsedContent = HomeUtils.GetLogoutUrl(pageInfo.HomeUrl, returnUrl); } else if (StringUtils.EqualsIgnoreCase(attributeName, RegisterUrl)) { var returnUrl = StlUtility.GetStlCurrentUrl(pageInfo, contextInfo.ChannelId, contextInfo.ContentId, contextInfo.ContentInfo); parsedContent = HomeUtils.GetRegisterUrl(pageInfo.HomeUrl, returnUrl); } else if (StringUtils.StartsWithIgnoreCase(attributeName, "TableFor"))// { if (StringUtils.EqualsIgnoreCase(attributeName, "TableForContent")) { parsedContent = pageInfo.PublishmentSystemInfo.AuxiliaryTableForContent; } else if (StringUtils.EqualsIgnoreCase(attributeName, "TableForGovInteract")) { parsedContent = pageInfo.PublishmentSystemInfo.AuxiliaryTableForGovInteract; } else if (StringUtils.EqualsIgnoreCase(attributeName, "TableForGovPublic")) { parsedContent = pageInfo.PublishmentSystemInfo.AuxiliaryTableForGovPublic; } else if (StringUtils.EqualsIgnoreCase(attributeName, "TableForJob")) { parsedContent = pageInfo.PublishmentSystemInfo.AuxiliaryTableForJob; } else if (StringUtils.EqualsIgnoreCase(attributeName, "TableForVote")) { parsedContent = pageInfo.PublishmentSystemInfo.AuxiliaryTableForVote; } } else if (StringUtils.StartsWithIgnoreCase(attributeName, "Site"))// { parsedContent = pageInfo.PublishmentSystemInfo.Additional.GetExtendedAttribute(attributeName.Substring(4)); } else { if (pageInfo.PublishmentSystemInfo.Additional.ContainsKey(attributeName)) { parsedContent = pageInfo.PublishmentSystemInfo.Additional.GetExtendedAttribute(attributeName); if (parsedContent.StartsWith("@")) { parsedContent = PageUtility.ParseNavigationUrl(pageInfo.PublishmentSystemId, parsedContent); } } else { var stlTagInfo = DataProvider.StlTagDao.GetStlTagInfo(pageInfo.PublishmentSystemId, attributeName) ?? DataProvider.StlTagDao.GetStlTagInfo(0, attributeName); if (!string.IsNullOrEmpty(stlTagInfo?.TagContent)) { var innerBuilder = new StringBuilder(stlTagInfo.TagContent); StlParserManager.ParseInnerContent(innerBuilder, pageInfo, contextInfo); parsedContent = innerBuilder.ToString(); } } } } catch { // ignored } return(parsedContent); }