public async Task <string> ParseAsync(IParseStlContext context) { var formName = string.Empty; var type = string.Empty; foreach (var name in context.StlAttributes.AllKeys) { var value = context.StlAttributes[name]; if (StringUtils.EqualsIgnoreCase(name, AttributeTitle) || StringUtils.EqualsIgnoreCase(name, AttributeName)) { formName = await context.ParseAsync(value); } else if (StringUtils.EqualsIgnoreCase(name, AttributeType)) { type = await context.ParseAsync(value); } } var formInfo = !string.IsNullOrEmpty(formName) ? await _formRepository.GetFormInfoByTitleAsync(context.SiteId, formName) : null; if (formInfo == null) { var formInfoList = await _formRepository.GetFormInfoListAsync(context.SiteId); if (formInfoList != null && formInfoList.Count > 0) { formInfo = formInfoList[0]; } } if (formInfo == null) { return(string.Empty); } var apiUrl = _pathManager.GetApiUrl(); if (string.IsNullOrEmpty(context.StlInnerHtml)) { var elementId = $"iframe_{StringUtils.GetShortGuid(false)}"; var libUrl = _pathManager.GetRootUrl("assets/form/lib/iframe-resizer-3.6.3/iframeResizer.min.js"); var pageUrl = _pathManager.GetRootUrl($"assets/form/templates/{type}/index.html?siteId={context.SiteId}&formId={formInfo.Id}&apiUrl={HttpUtility.UrlEncode(apiUrl)}"); return($@" <iframe id=""{elementId}"" frameborder=""0"" scrolling=""no"" src=""{pageUrl}"" style=""width: 1px;min-width: 100%;""></iframe> <script type=""text/javascript"" src=""{libUrl}""></script> <script type=""text/javascript"">iFrameResize({{log: false}}, '#{elementId}')</script> "); } return($@" <script> var $formConfigApiUrl = '{apiUrl}'; var $formConfigSiteId = {context.SiteId}; var $formConfigFormId = {formInfo.Id}; </script> {context.StlInnerHtml} "); }
public async Task <string> ParseAsync(IParseStlContext context) { var type = string.Empty; var url = string.Empty; var redirectUrl = await context.GetCurrentUrlAsync(); var attributes = new NameValueCollection(); foreach (var name in context.StlAttributes.AllKeys) { var value = context.StlAttributes[name]; if (StringUtils.EqualsIgnoreCase(name, AttributeType)) { type = await context.ParseAsync(value); } else if (StringUtils.EqualsIgnoreCase(name, AttributeUrl)) { url = await context.ParseAsync(value); } else if (StringUtils.EqualsIgnoreCase(name, AttributeRedirectUrl)) { redirectUrl = await context.ParseAsync(value); } else { attributes.Add(name, await context.ParseAsync(value)); } } var site = await _siteRepository.GetAsync(context.SiteId); var apiUrl = _pathManager.GetApiHostUrl(site, Constants.ApiPrefix); if (!string.IsNullOrEmpty(url)) { var parsedUrl = string.Empty; if (StringUtils.EqualsIgnoreCase(url, OAuthType.Weibo.Value)) { parsedUrl = $"{ApiUtils.GetAuthUrl(OAuthType.Weibo)}?redirectUrl={HttpUtility.UrlEncode(redirectUrl)}"; } else if (StringUtils.EqualsIgnoreCase(url, OAuthType.Weixin.Value)) { parsedUrl = $"{ApiUtils.GetAuthUrl(OAuthType.Weixin)}?redirectUrl={HttpUtility.UrlEncode(redirectUrl)}"; } else if (StringUtils.EqualsIgnoreCase(url, OAuthType.Qq.Value)) { parsedUrl = $"{ApiUtils.GetAuthUrl(OAuthType.Qq)}?redirectUrl={HttpUtility.UrlEncode(redirectUrl)}"; } else if (StringUtils.EqualsIgnoreCase(url, "logout")) { parsedUrl = _pathManager.GetApiHostUrl(site, $"assets/login/templates/logout/index.html?apiUrl={HttpUtility.UrlEncode(apiUrl)}&redirectUrl={HttpUtility.UrlEncode(redirectUrl)}"); } if (!string.IsNullOrEmpty(parsedUrl)) { if (context.IsStlEntity) { return(parsedUrl); } attributes["href"] = parsedUrl; return($@"<a {TranslateUtils.ToAttributesString(attributes)}>{context.StlInnerHtml}</a>"); } } if (string.IsNullOrEmpty(type)) { type = "login-account"; } var elementId = $"iframe_{StringUtils.GetShortGuid(false)}"; var libUrl = _pathManager.GetApiHostUrl(site, "assets/login/lib/iframe-resizer-3.6.3/iframeResizer.min.js"); var pageUrl = _pathManager.GetApiHostUrl(site, $"assets/login/templates/{type}/index.html?apiUrl={HttpUtility.UrlEncode(apiUrl)}&redirectUrl={HttpUtility.UrlEncode(redirectUrl)}"); return($@" <iframe id=""{elementId}"" frameborder=""0"" scrolling=""no"" src=""{pageUrl}"" style=""width: 1px;min-width: 100%;""></iframe> <script type=""text/javascript"" src=""{libUrl}""></script> <script type=""text/javascript"">iFrameResize({{log: false}}, '#{elementId}')</script> "); }
public async Task <string> ParseAsync(IParseStlContext context) { var channelIndex = string.Empty; var channelName = string.Empty; var type = string.Empty; var theme = string.Empty; foreach (var name in context.StlAttributes.AllKeys) { var value = context.StlAttributes[name]; if (StringUtils.EqualsIgnoreCase(name, ChannelIndex)) { channelIndex = await context.ParseAsync(value); } else if (StringUtils.EqualsIgnoreCase(name, ChannelName)) { channelName = await context.ParseAsync(value); } else if (StringUtils.EqualsIgnoreCase(name, AttributeType)) { type = await context.ParseAsync(value); } else if (StringUtils.EqualsIgnoreCase(name, AttributeTheme)) { theme = await context.ParseAsync(value); } } if (string.IsNullOrEmpty(theme)) { theme = "all"; } var channelId = context.ChannelId; var contentId = context.ContentId; if (!string.IsNullOrEmpty(channelIndex) || !string.IsNullOrEmpty(channelName)) { channelId = await _channelRepository.GetChannelIdAsync(context.SiteId, context.ChannelId, channelIndex, channelName); contentId = 0; } if (StringUtils.EqualsIgnoreCase(type, TypeCount)) { var count = _commentRepository.GetCountAsync(context.SiteId, channelId, contentId); return(count.ToString()); } var site = await _siteRepository.GetAsync(context.SiteId); var apiUrl = _pathManager.GetApiHostUrl(site, Constants.ApiPrefix); if (string.IsNullOrEmpty(context.StlInnerHtml)) { var elementId = $"iframe_{StringUtils.GetShortGuid(false)}"; var libUrl = _pathManager.GetApiHostUrl(site, "assets/comments/lib/iframe-resizer-3.6.3/iframeResizer.min.js"); var pageUrl = _pathManager.GetApiHostUrl(site, $"assets/comments/templates/{theme}/index.html?siteId={context.SiteId}&channelId={context.ChannelId}&contentId={context.ContentId}&apiUrl={HttpUtility.UrlEncode(apiUrl)}"); return($@" <iframe id=""{elementId}"" frameborder=""0"" scrolling=""no"" src=""{pageUrl}"" style=""width: 1px;min-width: 100%;""></iframe> <script type=""text/javascript"" src=""{libUrl}""></script> <script type=""text/javascript"">iFrameResize({{log: false}}, '#{elementId}')</script> "); } return($@" <script> var $commentsConfigApiUrl = '{apiUrl}'; var $commentsConfigSiteId = {context.SiteId}; var $commentsConfigChannelId = {context.ChannelId}; var $commentsConfigContentId = {context.ContentId}; </script> {context.StlInnerHtml} "); }
public async Task <string> ParseAsync(IParseStlContext context) { var url = string.Empty; var source = string.Empty; var title = string.Empty; var origin = string.Empty; var description = string.Empty; var image = string.Empty; var sites = "weibo, qq, qzone, douban"; var disabled = string.Empty; var wechatQrcodeTitle = string.Empty; var wechatQrcodeHelper = string.Empty; var attributes = new NameValueCollection(); foreach (var name in context.StlAttributes.AllKeys) { var value = context.StlAttributes[name]; if (StringUtils.EqualsIgnoreCase(name, AttributeUrl)) { url = await context.ParseAsync(value); } else if (StringUtils.EqualsIgnoreCase(name, AttributeSource)) { source = await context.ParseAsync(value); } else if (StringUtils.EqualsIgnoreCase(name, AttributeTitle)) { title = await context.ParseAsync(value); } else if (StringUtils.EqualsIgnoreCase(name, AttributeOrigin)) { origin = await context.ParseAsync(value); } else if (StringUtils.EqualsIgnoreCase(name, AttributeDescription)) { description = await context.ParseAsync(value); } else if (StringUtils.EqualsIgnoreCase(name, AttributeImage)) { image = await context.ParseAsync(value); } else if (StringUtils.EqualsIgnoreCase(name, AttributeSites)) { sites = await context.ParseAsync(value); } else if (StringUtils.EqualsIgnoreCase(name, AttributeDisabled)) { disabled = await context.ParseAsync(value); } else if (StringUtils.EqualsIgnoreCase(name, AttributeWechatQrcodeTitle)) { wechatQrcodeTitle = await context.ParseAsync(value); } else if (StringUtils.EqualsIgnoreCase(name, AttributeWechatQrcodeHelper)) { wechatQrcodeHelper = await context.ParseAsync(value); } else { attributes[name] = await context.ParseAsync(value); } } var settings = await _shareManager.GetSettingsAsync(context.SiteId); var site = await _siteRepository.GetAsync(context.SiteId); if (settings.IsWxShare) { sites += ",wechat"; } var cssUrl = _pathManager.GetApiHostUrl(site, "/assets/share/css/share.min.css"); var jsUrl = _pathManager.GetApiHostUrl(site, "/assets/share/js/social-share.min.js"); context.HeadCodes[ShareManager.PluginId] = @$ "<link rel=" "stylesheet" " href=" "{cssUrl}" ">"; context.FootCodes[ShareManager.PluginId] = @$ "<script type=" "text/javascript" " src=" "{jsUrl}" "></script>"; Content content = null; if (context.ContentId > 0) { if (string.IsNullOrEmpty(title)) { if (content == null) { content = await _contentRepository.GetAsync(site, context.ChannelId, context.ContentId); } if (content != null) { title = content.Title; } } if (string.IsNullOrEmpty(image)) { if (content == null) { content = await _contentRepository.GetAsync(site, context.ChannelId, context.ContentId); } if (content != null && !string.IsNullOrEmpty(content.ImageUrl)) { image = await _pathManager.ParseSiteUrlAsync(site, content.ImageUrl, false); image = PageUtils.AddProtocolToUrl(image); } } if (string.IsNullOrEmpty(description)) { if (content == null) { content = await _contentRepository.GetAsync(site, context.ChannelId, context.ContentId); } if (content != null) { description = content.Summary; if (string.IsNullOrEmpty(description)) { description = StringUtils.MaxLengthText(StringUtils.StripTags(content.Body), 50); } } } } if (string.IsNullOrEmpty(title)) { title = settings.DefaultTitle; } if (string.IsNullOrEmpty(image) && !string.IsNullOrEmpty(settings.DefaultImageUrl)) { image = await _pathManager.ParseSiteUrlAsync(site, settings.DefaultImageUrl, false); image = PageUtils.AddProtocolToUrl(image); } if (string.IsNullOrEmpty(description)) { description = settings.DefaultDescription; } if (!string.IsNullOrEmpty(url)) { attributes["data-url"] = url; } if (!string.IsNullOrEmpty(source)) { attributes["data-source"] = source; } if (!string.IsNullOrEmpty(title)) { attributes["data-title"] = title; } if (!string.IsNullOrEmpty(origin)) { attributes["data-origin"] = origin; } if (!string.IsNullOrEmpty(description)) { attributes["data-description"] = description; } if (!string.IsNullOrEmpty(image)) { attributes["data-image"] = image; } if (!string.IsNullOrEmpty(sites)) { attributes["data-sites"] = sites; } if (!string.IsNullOrEmpty(disabled)) { attributes["data-disabled"] = disabled; } if (!string.IsNullOrEmpty(wechatQrcodeTitle)) { attributes["data-wechat-qrcode-title"] = wechatQrcodeTitle; } if (!string.IsNullOrEmpty(wechatQrcodeHelper)) { attributes["data-data-wechat-qrcode-helper"] = wechatQrcodeHelper; } return($@"<div class=""social-share"" {TranslateUtils.ToAttributesString(attributes)}></div>"); }