public static dynamic ToJSON(this PageElement tmpl) { return(new { name = tmpl.Name, title = tmpl.Title != null?GE.GetContent(tmpl.Title.Text) : "", desc = tmpl.Description != null?GE.GetContent(tmpl.Description.Text) : "", icon = tmpl.Icon, picture = tmpl.Image }); }
public static dynamic ToJSON(this WidgetPackage pkg, IWidgetDescriptorRepository repository) { var widget = pkg.Model; var Url = UrlUtility.CreateUrlHelper(); //var repository = WebSiteContext.Current.DataContext.WidgetDescriptors; var installPath = pkg.Category + "\\" + pkg.Name; return(new { id = pkg.Name, category = pkg.Category, uid = widget.ID, name = new { shortname = widget.Name != null ? widget.Name.ShortName : "Unknown", fullname = widget.Name != null ? widget.Name.FullName : "Unknown" }, icons = widget.Icons != null ? (widget.Icons.Select(i => new { src = Url.Content(pkg.ResolveUri(i.Source)), width = i.Width, height = i.Height })) : null, desc = GE.GetContent(widget.Description), author = widget.Author != null ? new //The user object is read from remote { name = widget.Author.Name, href = widget.Author.Uri, email = widget.Author.Email } : null, totalUses = repository.InusingWidgetsCount(installPath), ratings = 0, // from remote installed = repository.Contains(w => w.UID.Equals(widget.ID, StringComparison.OrdinalIgnoreCase)), version = widget.Version, languages = pkg.GetSupportLanguages(), //signed = pkg.HasSigned, //verified = pkg.Verify(), licenses = widget.Licenses != null ? (widget.Licenses.Select(l => new { name = l.Text, href = l.Source })) : null //modified = tmpl.Modified }); }
/// <summary> /// Render the sitemenu element that on the top of the web page. /// </summary> /// <param name="htmlAttributes">The html attributes for output element.</param> /// <returns></returns> public static HelperResult SiteMenu(object htmlAttributes = null) { var _web = AppModel.Get().Webs["home"]; var locale = CurrentPage.Culture; var curPage = AppModel.Get().CurrentPage; var currentID = curPage != null ? curPage.ID : 0; return(new HelperResult(w => { using (var writer = new HtmlTextWriter(w)) { var pages = _web.Pages.Where(p => p.ShowInMenu && p.ParentID == 0 && p.Locale.Equals(locale, StringComparison.OrdinalIgnoreCase)).OrderBy(p => p.Pos).ToList(); writer.WriteBeginTag("ul"); if (htmlAttributes != null) { var attrs = ObjectHelper.ConvertObjectToDictionary(htmlAttributes); foreach (var attr in attrs) { var key = attr.Key; if (key.StartsWith("data_")) { key = key.Replace("_", "-"); } writer.WriteAttribute(key, attr.Value != null ? attr.Value.ToString() : ""); } } writer.Write(HtmlTextWriter.TagRightChar); foreach (var p in pages) { if (!IsAccessibleToUser(p)) { continue; } #region render node var path = string.Format("~/{0}/{1}/{2}.html", p.Web.Name, p.Locale, p.Slug); writer.WriteBeginTag("li"); if (curPage != null) { var parentPath = p.Path + "/"; if (!string.IsNullOrEmpty(curPage.Path) && (curPage.Path.StartsWith(parentPath, StringComparison.OrdinalIgnoreCase) || p.ID == curPage.ID)) { writer.WriteAttribute("class", "d-state-active"); } } writer.Write(HtmlTextWriter.TagRightChar); writer.WriteBeginTag("a"); writer.WriteAttribute("data-id", p.ID.ToString()); if (p.NoFollow) { writer.WriteAttribute("rel", "nofollow"); } else { if (!string.IsNullOrEmpty(Request.Browser.Browser) && Request.Browser.Browser.Equals("chrome", StringComparison.OrdinalIgnoreCase)) { writer.WriteAttribute("rel", "preload"); } else { writer.WriteAttribute("rel", "prefetch"); } } if (!string.IsNullOrEmpty(p.LinkTo)) { writer.WriteAttribute("href", p.LinkTo); } else { writer.WriteAttribute("href", Href(path)); } writer.Write(HtmlTextWriter.TagRightChar); writer.WriteEncodedText(GE.GetContent(p.Title)); writer.WriteEndTag("a"); writer.WriteEndTag("li"); #endregion } writer.WriteEndTag("ul"); } })); }
private static void RenderNode(HtmlTextWriter writer, WebPage p, IEnumerable <WebPage> pages, bool withAttrs = true, bool showImg = true, WebPage curPage = null, int dataType = 1) { //var urlHelper = new UrlHelper(Context.Request); var path = string.Format("~/{0}/{1}/{2}.html", p.Web.Name, p.Locale, p.Slug); writer.WriteBeginTag("li"); if (!object.ReferenceEquals(curPage, null) && !object.ReferenceEquals(p.Path, null) && !object.ReferenceEquals(curPage.Path, null)) { var parentPath = p.Path + "/"; if (curPage.Path.StartsWith(parentPath, StringComparison.OrdinalIgnoreCase) || p.ID == curPage.ID) { writer.WriteAttribute("class", "d-state-active"); } } writer.Write(HtmlTextWriter.TagRightChar); writer.WriteBeginTag("a"); writer.WriteAttribute("data-id", p.ID.ToString()); if (withAttrs) { writer.WriteAttribute("data-parentId", p.ParentID.ToString()); writer.WriteAttribute("data-in-menu", p.ShowInMenu.ToString().ToLower()); writer.WriteAttribute("data-in-sitemap", p.ShowInSitemap.ToString().ToLower()); writer.WriteAttribute("data-static", p.IsStatic.ToString().ToLower()); writer.WriteAttribute("data-shared", p.IsShared.ToString().ToLower()); writer.WriteAttribute("data-title", p.Title); writer.WriteAttribute("data-desc", p.Description); //writer.WriteAttribute("data-slug", p.Slug.ToLower()); writer.WriteAttribute("data-path", Href(path)); writer.WriteAttribute("data-anonymous", p.AllowAnonymous.ToString().ToLower()); } else { if (p.NoFollow) { writer.WriteAttribute("rel", "nofollow"); } else { if (!string.IsNullOrEmpty(Request.Browser.Browser) && Request.Browser.Browser.Equals("chrome", StringComparison.OrdinalIgnoreCase)) { writer.WriteAttribute("rel", "preload"); } else { writer.WriteAttribute("rel", "prefetch"); } } if (!string.IsNullOrEmpty(p.LinkTo)) { writer.WriteAttribute("href", p.LinkTo); } else { writer.WriteAttribute("href", Href(path)); } } writer.Write(HtmlTextWriter.TagRightChar); if (showImg) { if (!string.IsNullOrEmpty(p.IconUrl)) { writer.WriteBeginTag("img"); writer.WriteAttribute("src", Href(p.IconUrl)); writer.WriteAttribute("alt", p.Title); writer.Write(HtmlTextWriter.SelfClosingTagEnd); } } writer.WriteEncodedText(GE.GetContent(p.Title)); writer.WriteEndTag("a"); if (dataType == 1) { var children = pages.Where(page => page.ParentID == p.ID).OrderBy(page => page.Pos).ToList(); if (children.Count > 0) { writer.WriteFullBeginTag("ul"); foreach (var child in children) { RenderNode(writer, child, pages, withAttrs, showImg); } writer.WriteEndTag("ul"); } } writer.WriteEndTag("li"); }