public IActionResult Index(string url) { _webSite.Logger?.LogInformation($"index action {Request.Path.Value}"); if (Request.Query["reloadpages"] == "true") { _webSite.ReloadPages(); } if (string.IsNullOrWhiteSpace(url) || url == "/") { _webSite.Logger?.LogVerbose("Homepage"); url = _webSite.Configuration.DefaultPage; } SitePage page = _webSite.GetPageByUrl(url, _webSite.IsAuthenticated(User)); ViewBag.CurrentUrl = page.Url; if (_webSite.Configuration.RedirectToFirstSub && page.Pages.Any()) { return(Redirect(page.Pages.First().Url)); } if (page.Url == "404") { Response.StatusCode = 404; } return(View(page.Template, page)); }
public override void Process(TagHelperContext context, TagHelperOutput output) { //Set Content edit properties on tags when logged in if (_webSite.IsAuthenticated(ViewContext.HttpContext.User)) { if (!string.IsNullOrWhiteSpace(Template)) { output.Attributes.Add("data-miniwebtemplate", Template); } if (!string.IsNullOrWhiteSpace(Section)) { output.Attributes.Add("data-miniwebsection", Section); } } //load the content items in the specified section if (!string.IsNullOrWhiteSpace(Section)) { //contextualize the HtmlHelper for the current ViewContext (_htmlHelper as ICanHasViewContext)?.Contextualize(ViewContext); //get out the current ViewPage for the Model. var view = ViewContext.View as RazorView; var viewPage = view?.RazorPage as RazorPage <SitePage>; output.Content.Clear(); if (viewPage != null) { var sectionContent = SectionContent(_htmlHelper, viewPage.Model, Section); output.Content.AppendEncoded(sectionContent); } } }
public override void Process(TagHelperContext context, TagHelperOutput output) { var items = Enumerable.Empty <SitePage>(); if (MenuRoot == "/") { items = _webSite.PageHierarchy.Where(p => p.VisibleInMenu() || _webSite.IsAuthenticated(ViewContext.HttpContext.User)); } else if (_webSite.Pages.Any(p => ("/" + p.Url) == MenuRoot)) { items = _webSite.Pages.First(p => ("/" + p.Url) == MenuRoot).Pages.Where(p => p.VisibleInMenu() || _webSite.IsAuthenticated(ViewContext.HttpContext.User)); } else { _webSite.Logger?.LogWarning($"No menuitems found for {MenuRoot}"); } if (items.Any()) { (_htmlHelper as ICanHasViewContext)?.Contextualize(ViewContext); foreach (var page in items) { output.Content.Append(_htmlHelper.Partial(MenuItemTemplate, page)); } } else { output.SuppressOutput(); } }
public override void Process(TagHelperContext context, TagHelperOutput output) { if (_webSite.IsAuthenticated(ViewContext.HttpContext.User)) { output.TagMode = TagMode.StartTagAndEndTag; //add the own contents. output.Content.SetContent(context.GetChildContentAsync().Result); (_htmlHelper as ICanHasViewContext)?.Contextualize(ViewContext); output.PreContent.Append(_htmlHelper.Partial(MiniWebFileProvider.ADMIN_FILENAME)); if (!IgnoreAdminStart) { output.Content.AppendEncoded($"<script>$(function(){{$('{MiniWebAdminTag}').miniwebAdmin();}});</script>"); } } else { output.SuppressOutput(); } }
public override void Process(TagHelperContext context, TagHelperOutput output) { //fill property title and content on specified tags if (!string.IsNullOrWhiteSpace(Property)) { var view = ViewContext.View as RazorView; var viewItem = view.RazorPage as RazorPage <ContentItem>; var htmlContent = viewItem.Model.GetValue(Property, context.GetChildContentAsync().Result?.GetContent(HtmlEncoder.Default)); output.Content.Clear(); output.Content.AppendEncoded(htmlContent); foreach (var attr in EditAttributes) { output.Attributes[attr].Value = viewItem.Model.GetValue(Property + ":" + attr, context.AllAttributes[attr]?.Value?.ToString()); } } //Set Content edit properties on tags when logged in if (_webSite.IsAuthenticated(ViewContext.HttpContext.User)) { if (!string.IsNullOrWhiteSpace(Property)) { output.Attributes.Add("data-miniwebprop", Property); } if (!string.IsNullOrWhiteSpace(EditType)) { output.Attributes.Add("data-miniwebedittype", EditType); } if (EditAttributes.Any()) { output.PostElement.AppendEncoded("<div class=\"miniweb-attributes\">"); foreach (var attr in EditAttributes) { var attrEditItem = string.Format("<span data-miniwebprop=\"{0}:{1}\">{2}</span>", Property, attr, output.Attributes[attr].Value); output.PostElement.AppendEncoded(attrEditItem); } output.PostElement.AppendEncoded("</div>"); } } }
public async Task Invoke(HttpContext context) { var path = context.Request.Path.Value; //TODO(RC): fix application paths with ~/ if (_miniWebSite.IsAuthenticated(context.User) && path.StartsWith("/miniweb-resource/")) { var resource = Path.GetFileName(path); var fileInfo = _provider.GetFileInfo($"Resources/{resource}"); if (fileInfo.Exists) { using (var stream = fileInfo.CreateReadStream()) { StreamReader reader = new StreamReader(stream); //TODO(RC): read from file? string contentType = "text/css"; if (resource.EndsWith(".js")) { contentType = "application/javascript"; } _miniWebSite.Logger?.LogVerbose($"Embedded: {resource}"); context.Response.ContentType = contentType; await context.Response.WriteAsync(reader.ReadToEnd()); } } else { _miniWebSite.Logger?.LogWarning($"Embedded resource not found: {resource}"); context.Response.StatusCode = 404; await context.Response.WriteAsync("404:" + resource); } } else { await _next(context); } }