public async Task ParseAsync(IParseContext context) { var rules = await _ruleRepository.GetAllAsync(context.SiteId); if (rules == null || rules.Count == 0) { return; } var isChannel = false; foreach (var rule in rules) { if (rule.IsAllChannels) { isChannel = true; break; } if (rule.BlockChannels != null && rule.BlockChannels.Contains(context.ChannelId)) { isChannel = true; break; } } if (!isChannel) { return; } var site = await _siteRepository.GetAsync(context.SiteId); var urlPrefix = _pathManager.GetApiHostUrl(site, "/assets/block"); var apiUrl = _pathManager.GetApiHostUrl(site, Constants.ApiPrefix); context.HeadCodes[BlockManager.PluginId] = $@" <style>body{{display: none !important}}</style> <script src=""{urlPrefix}/lib/es6-promise.auto.min.js"" type=""text/javascript""></script> <script src=""{urlPrefix}/lib/axios-0.18.0.min.js"" type=""text/javascript""></script> <script src=""{urlPrefix}/lib/sweetalert2-7.28.4.all.min.js"" type=""text/javascript""></script> <script src=""{urlPrefix}/block.js"" data-api-url=""{apiUrl}"" data-site-id=""{context.SiteId}"" type=""text/javascript""></script> "; }
public async Task ParseAsync(IParseContext context) { if (context.TemplateType != TemplateType.ContentTemplate || context.ContentId <= 0) { return; } var site = await _siteRepository.GetAsync(context.SiteId); var apiUrl = _pathManager.GetApiHostUrl(site, Constants.ApiPrefix, $"/hits/{context.SiteId}/{context.ChannelId}/{context.ContentId}"); context.FootCodes.TryAdd(HitsManager.PluginId, $@"<script src=""{apiUrl}"" type=""text/javascript""></script>"); }
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>"); }
public static string GetSearchApiUrl(Site site, IPathManager pathManager) { return(pathManager.GetApiHostUrl(site, Constants.ApiPrefix, Constants.ApiStlPrefix, Constants.RouteStlActionsSearch)); }
public async Task ParseAsync(IParseContext context) { var settings = await _shareManager.GetSettingsAsync(context.SiteId); if (!settings.IsWxShare) { return; } var site = await _siteRepository.GetAsync(context.SiteId); var title = site.SiteName; var description = string.Empty; var imageUrl = string.Empty; if (context.ContentId > 0) { var content = await _contentRepository.GetAsync(site, context.ChannelId, context.ContentId); if (content != null) { title = content.Title; description = content.Summary; if (string.IsNullOrEmpty(description)) { description = StringUtils.MaxLengthText(StringUtils.StripTags(content.Body), 50); } if (!string.IsNullOrEmpty(content.ImageUrl)) { imageUrl = await _pathManager.ParseSiteUrlAsync(site, content.ImageUrl, false); imageUrl = PageUtils.AddProtocolToUrl(imageUrl); } } } if (string.IsNullOrEmpty(title)) { title = settings.DefaultTitle; } if (string.IsNullOrEmpty(imageUrl) && !string.IsNullOrEmpty(settings.DefaultImageUrl)) { imageUrl = await _pathManager.ParseSiteUrlAsync(site, settings.DefaultImageUrl, false); imageUrl = PageUtils.AddProtocolToUrl(imageUrl); } if (string.IsNullOrEmpty(description)) { description = settings.DefaultDescription; } var axiosJsUrl = _pathManager.GetSiteFilesUrl(site, Libraries.AxiosJs); var wxShareJsUrl = _pathManager.GetApiHostUrl(site, "assets/share/js/wxShare.js"); var apiUrl = _pathManager.GetApiHostUrl(site, "api/share/wx"); context.FootCodes.TryAdd($"{ShareManager.PluginId}_weixinShare", $@" <script> var wxShare = {{title: '{StringUtils.ToJsString(title)}', desc: '{StringUtils.ToJsString(description)}', imgUrl: '{StringUtils.ToJsString(imageUrl)}', siteId: {context.SiteId}, apiUrl: '{StringUtils.ToJsString(apiUrl)}' }}; </script> <script src=""{axiosJsUrl}""></script> <script src=""//res.wx.qq.com/open/js/jweixin-1.6.0.js""></script> <script src=""{wxShareJsUrl}""></script> "); }
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]; } } var site = await _siteRepository.GetAsync(context.SiteId); if (formInfo == null || site == null) { return(string.Empty); } var apiUrl = _pathManager.GetApiHostUrl(site, Constants.ApiPrefix); if (string.IsNullOrEmpty(context.StlInnerHtml)) { var elementId = $"iframe_{StringUtils.GetShortGuid(false)}"; var libUrl = _pathManager.GetApiHostUrl(site, "assets/form/lib/iframe-resizer-3.6.3/iframeResizer.min.js"); var pageUrl = _pathManager.GetApiHostUrl(site, $"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} "); }