示例#1
0
        private static bool IsAccessibleToUser(WebPage page)
        {
            //if (node.Equals(RootNode)) return true;
            //var page = GetPageFromKey(GetIDFromKey(node.Key));

            if (page.AllowAnonymous)
            {
                return(true);
            }

            if (Request.IsAuthenticated)
            {
                if (roleTable == null)
                {
                    PreloadRoleTable();
                }
                if (roleTable.ContainsKey(page.ID))
                {
                    var roles = roleTable[page.ID];
                    foreach (var role in roles)
                    {
                        if (AppModel.Get().User.IsInRole(role))
                        {
                            return(true);
                        }
                    }
                }
                //page.Roles.Contains(AppModel.Get().User.ro
            }
            return(false);
        }
示例#2
0
        public ActionResult SiteSettings()
        {
            var web = AppModel.Get().CurrentWeb;

            //var defaultLocale = web.
            //if (defa
            return(View(web));
        }
示例#3
0
 public static MvcHtmlString UserLink(this HtmlHelper helper, string userName)
 {
     if (!string.IsNullOrEmpty(userName))
     {
         var user     = AppModel.Get().Users[userName];
         var url      = new UrlHelper(helper.ViewContext.RequestContext);
         var dispName = user.DefaultProfile.DisplayName;
         if (string.IsNullOrEmpty(dispName))
         {
             dispName = user.UserName;
         }
         return(MvcHtmlString.Create(string.Format("<a href=\"{0}\" role=\"link\" data-icon-left=\"d-icon-user\">{1}</a>", url.Content("~/profiles/" + userName), dispName)));
     }
     return(MvcHtmlString.Empty);
 }
        public ActionResult DataFileSchema(string file, string type)
        {
            if (string.IsNullOrEmpty(file))
            {
                throw new ArgumentNullException("file");
            }

            if (string.IsNullOrEmpty(file))
            {
                throw new ArgumentNullException("type");
            }

            var pkg = AppModel.Get().ContentTypes[type];

            ViewBag.FileUri = new Uri(file);
            return(PartialView(pkg));
        }
示例#5
0
        private static void PreloadRoleTable()
        {
            //int[] pIDs = AppModel.Get().CurrentWeb.Pages.Where(p => !p.AllowAnonymous).Select(p => p.ID).ToArray();
            //var roles = AppModel.Get().DataContext.WebPages.GetRoles(pIDs);
            var pages = AppModel.Get().CurrentWeb.Pages.Where(p => !p.AllowAnonymous);

            roleTable = new Dictionary <int, string[]>();
            foreach (var p in pages)
            {
                var roles = p.Roles;
                if (roles != null && roles.Length > 0)
                {
                    roleTable.Add(p.ID, p.Roles);
                }
            }

            //var roleGroups = roles.GroupBy(r => r.PageID);
            //foreach (var roleGroup in roleGroups)
            //{
            //    roleTable.Add(roleGroup.Key, roleGroup.Select(r => r.RoleName).ToArray());
            //}
        }
示例#6
0
        public ActionResult ViewProfile(string user)
        {
            var _user = AppModel.Get().Users[user];

            return(PartialView(_user));
        }
        public ActionResult Layouts(int id)
        {
            var page = AppModel.Get().CurrentWeb.FindPage(id);

            return(PartialView(page));
        }
示例#8
0
        /// <summary>
        /// Render the widget to current response output.
        /// </summary>
        /// <param name="writer"></param>
        public override void Render(HtmlTextWriter writer)
        {
            var locale = App.Get().Context.Locale;

            if (!string.IsNullOrEmpty(locale))
            {
                App.Get().SetCulture(locale);
            }

            bool isPreviewMode = false;
            Dictionary <string, PropertyDescriptor> propertyDescriptors = null;
            Dictionary <string, object>             userdata            = new Dictionary <string, object>();

            var bag = Html.ViewContext.Controller.ViewBag;

            if (bag != null)
            {
                if (bag.PropertyDescriptors != null)
                {
                    propertyDescriptors = bag.PropertyDescriptors as Dictionary <string, PropertyDescriptor>;
                    if (propertyDescriptors != null)
                    {
                        foreach (var key in propertyDescriptors.Keys)
                        {
                            userdata.Add(key, propertyDescriptors[key].Value);
                        }
                    }
                }

                if (bag.IsPreview != null)
                {
                    isPreviewMode = bag.IsPreview;
                }

                Model = bag.WidgetInstance;
            }

            var widgetHelper = new WidgetHelper()
            {
                Model               = Model,
                UserPreferences     = userdata,
                PropertyDescriptors = propertyDescriptors
            };

            if (isPreviewMode)
            {
                if (!PreviewTemplate.IsEmpty)
                {
                    PreviewTemplate.WriteTo(widgetHelper, writer);
                }
                else
                {
                    if (!ContentTemplate.IsEmpty)
                    {
                        ContentTemplate.WriteTo(widgetHelper, writer);
                    }
                }
            }
            else
            {
                if (IsDesignMode)
                {
                    if (userdata.Count > 0 && this.Model.WidgetDescriptor.WidgetType == 1)
                    {
                        var urlhelper = new UrlHelper(Request.RequestContext);

                        writer.WriteBeginTag("form");
                        writer.WriteAttribute("class", "d-widget-prefs d-tran-fast d-form");
                        writer.WriteAttribute("data-ajax", "true");
                        writer.WriteAttribute("data-ajax-url", urlhelper.Content("~/api/" + AppModel.Get().Context.Website + "/widgets/apply"));
                        writer.WriteAttribute("data-ajax-method", "post");
                        //writer.WriteAttribute("data-ajax-begin", "$.loading()");
                        writer.WriteAttribute("data-ajax-success", "$('#widget_" + this.Model.ID.ToString() + "').widget('refresh');" + (AutoSave ? "" : "$.closePanels();"));
                        if (this.HideUserPreferences)
                        {
                            writer.WriteAttribute("data-hidden", "true");
                        }

                        if (this.AutoSave)
                        {
                            writer.WriteAttribute("data-auto-save", "true");
                            writer.WriteAttribute("onchange", "$(this).submit();");
                        }

                        //    writer.WriteAttribute("data-allow-pop", "false");

                        writer.Write(HtmlTextWriter.TagRightChar);

                        writer.WriteBeginTag("input");
                        writer.WriteAttribute("type", "hidden");
                        writer.WriteAttribute("name", "id");
                        writer.WriteAttribute("value", Model.ID.ToString());
                        writer.Write(HtmlTextWriter.SelfClosingTagEnd);

                        if (!UserPreferencesTemplate.IsEmpty)
                        {
                            UserPreferencesTemplate.WriteTo(widgetHelper, writer);
                        }
                        else
                        {
                            foreach (var key in propertyDescriptors.Keys)
                            {
                                if (!propertyDescriptors[key].IsReadonly)
                                {
                                    RenderPropertyControl(writer, widgetHelper, propertyDescriptors[key]);
                                }
                            }
                        }

                        writer.WriteEndTag("form");
                    }

                    if (!DesignTemplate.IsEmpty)
                    {
                        DesignTemplate.WriteTo(widgetHelper, writer);
                    }
                    else
                    if (!ContentTemplate.IsEmpty)
                    {
                        ContentTemplate.WriteTo(widgetHelper, writer);
                    }
                    writer.Write("<script type=\"text/javascript\">$(function(){ $('#widget_" + this.Model.ID.ToString() + "').taoUI(); });</script>");
                    //writer.Write("<script type=\"text/javascript\">$(function(){ $('#widget_" + this.Model.ID.ToString() + "').unobtrusive_ajax().taoUI(); });</script>");
                }
                else
                {
                    if (Model.Cached)
                    {
                        //Render cachable widget eg:Html widget
                        var cachedHtml = "";
                        var cachedKey  = "widget" + Model.ID.ToString() + "_caching_html";
                        if (Context.Cache[cachedKey] != null)
                        {
                            cachedHtml = Context.Cache[cachedKey].ToString();
                        }
                        else
                        {
                            var cachedBuilder = new StringBuilder();
                            using (var cachedTextWriter = new System.IO.StringWriter(cachedBuilder))
                            {
                                using (var cachedWriter = new Html32TextWriter(cachedTextWriter))
                                {
                                    if (!ContentTemplate.IsEmpty)
                                    {
                                        ContentTemplate.WriteTo(widgetHelper, cachedWriter);
                                    }
                                    if (!HeaderTemplate.IsEmpty && Model.ShowHeader)
                                    {
                                        cachedWriter.Write("<div id=\"widget_" + this.Model.ID.ToString() + "_header_holder\" style=\"display:none;\">");
                                        HeaderTemplate.WriteTo(widgetHelper, cachedWriter);
                                        cachedWriter.Write("</div>");
                                        cachedWriter.Write("<script type=\"text/javascript\">$(function(){ if ($('#widget_" + this.Model.ID.ToString() + "').find('.d-widget-header').length) { $('#widget_" + this.Model.ID.ToString() + "').find('.d-widget-header').empty().append($('#widget_" + this.Model.ID.ToString() + "_header_holder').children());$('#widget_" + this.Model.ID.ToString() + "_header_holder').remove(); }  });</script>");
                                    }
                                }
                            }
                            cachedHtml = cachedBuilder.ToString();
                            Context.Cache.Add(cachedKey, cachedHtml, null, DateTime.Now.AddMinutes(5), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Default, null);
                        }
                        writer.Write(cachedHtml);
                    }
                    else
                    {
                        if (!ContentTemplate.IsEmpty)
                        {
                            ContentTemplate.WriteTo(widgetHelper, writer);
                        }

                        if (!HeaderTemplate.IsEmpty && Model.ShowHeader)
                        {
                            writer.Write("<div id=\"widget_" + this.Model.ID.ToString() + "_header_holder\" style=\"display:none;\">");
                            HeaderTemplate.WriteTo(widgetHelper, writer);
                            writer.Write("</div>");
                            writer.Write("<script type=\"text/javascript\">$(function(){ if ($('#widget_" + this.Model.ID.ToString() + "').find('.d-widget-header').length) { $('#widget_" + this.Model.ID.ToString() + "').find('.d-widget-header').empty().append($('#widget_" + this.Model.ID.ToString() + "_header_holder').children());$('#widget_" + this.Model.ID.ToString() + "_header_holder').remove(); }  });</script>");
                        }
                    }
                }
            }
            //writer.Write(System.Web.Optimization.Scripts.Render("~/bundles/jqueryval"));
            //writer.Write(html.StartupScripts().ToString());
        }
示例#9
0
        /// <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");
                }
            }));
        }
示例#10
0
        /// <summary>
        /// Render inline path navigation elements for current page.
        /// </summary>
        /// <param name="htmlAttributes">The html attributes for output element.</param>
        /// <param name="showCurrent">Show current states</param>
        /// <param name="showRoot">Show the root node of the path.</param>
        /// <returns></returns>
        public static HelperResult RenderPagePath(object htmlAttributes = null, bool showCurrent = true, bool showRoot = true)
        {
            return(new HelperResult(writer =>
            {
                var curPage = AppModel.Get().CurrentPage;
                if (curPage != null)
                {
                    var parents = curPage.Parents().Where(p => !p.IsShared).OrderBy(p => p.Path).ToList().Select(n =>
                    {
                        var wrapper = AppModel.Get().Wrap(n);
                        var element = new XElement("li", new XElement("a", wrapper.Title, new XAttribute("href", wrapper.Url)));

                        if (!string.IsNullOrEmpty(wrapper.Description))
                        {
                            element.Add(new XAttribute("title", wrapper.Description));
                        }

                        return element;
                    });

                    var ul = new XElement("ul");

                    if (showRoot)
                    {
                        ul.Add(new XElement("li", new XElement("a", AppModel.Get().CurrentWeb.Title,
                                                               new XAttribute("href", UrlHelper.GenerateContentUrl(AppModel.Get().CurrentWeb.Url, Context))
                                                               )));
                    }


                    if (htmlAttributes != null)
                    {
                        var attrs = htmlAttributes.ToDictionary();
                        foreach (var attr in attrs.Keys)
                        {
                            ul.Add(new XAttribute(attr.Replace("_", "-"), attrs[attr]));
                        }
                    }

                    if (parents.Count() > 0)
                    {
                        ul.Add(parents);
                    }

                    if (showCurrent && !curPage.IsShared)
                    {
                        ul.Add(new XElement("li", new XElement("a", curPage.Title,
                                                               new XAttribute("href", "javascript:void(0);")
                                                               ), new XAttribute("class", "d-link d-state-active")));
                    }

                    var ctx = AppModel.Get().Context;
                    if (ctx.View != null)
                    {
                        ul.Add(new XElement("li", new XElement("a", ctx.View.Title,
                                                               new XAttribute("href", UrlHelper.GenerateContentUrl(ctx.View.Url, Context)))));
                    }

                    //Render context form , item and views
                    if (ctx.DataItem != null)
                    {
                        var list = ctx.DataItem.Parent;
                        if (list.IsHierarchy)
                        {
                            var parentItems = ctx.DataItem.Parents();
                            if (parentItems != null)
                            {
                                var itemParentEles = parentItems.ToList()
                                                     .Select(p =>
                                {
                                    var itemWrapper = AppModel.Get().Wrap(p);
                                    var title = itemWrapper.GetDefaultTitleValue();
                                    var element = new XElement("li", new XElement("a", title,
                                                                                  new XAttribute("href",
                                                                                                 UrlHelper.GenerateContentUrl(itemWrapper.Url, Context))));
                                    return element;
                                });
                                if (itemParentEles.Count() > 0)
                                {
                                    ul.Add(itemParentEles);
                                }
                            }
                        }


                        ul.Add(new XElement("li",
                                            new XElement("a", ctx.DataItem.GetDefaultTitleValue(),
                                                         new XAttribute("href", DNA.Utility.UrlUtility.CreateUrlHelper().Action("Catalog", "Contents", new { Area = "", name = list.Name, website = list.Web.Name, locale = list.Locale, id = ctx.DataItem.ID })),
                                                         new XAttribute("data-rel", "panel"),
                                                         new XAttribute("data-panel-fill", "true"),
                                                         new XAttribute("data-panel-display", "push"),
                                                         new XAttribute("data-panel-title", ctx.DataItem.Parent.Title)
                                                         ),
                                            new XAttribute("class", "d-state-active")));
                    }


                    if (ul.HasElements)
                    {
                        writer.Write(ul.OuterXml());
                    }
                }
            }));
        }
示例#11
0
        /// <summary>
        /// Render HTML ui element for web page structure.
        /// </summary>
        /// <param name="web">The parent web instance.</param>
        /// <param name="withAttributes"></param>
        /// <param name="showimg">Whether show image on the left of the node item.</param>
        /// <param name="ismenu">Show as menu</param>
        /// <param name="issitemap">Show as sitemap</param>
        /// <param name="htmlAttributes">The html attributes for output element.</param>
        /// <param name="dataType">The menu item filter:1:all pages. 2:root pages (the top level pages.) 3:show children pages</param>
        /// <returns></returns>
        public static HelperResult GetHtml(Web web = null, bool withAttributes = false, bool showimg = false, bool ismenu = false, bool issitemap = false, object htmlAttributes = null, int dataType = 1)
        {
            var _web        = new WebDecorator(web == null ? AppModel.Get().Context.Web : web, AppModel.Get().DataContext);
            var locale      = CurrentPage.Culture;// _web.DefaultLocale;
            var currentPage = AppModel.Get().CurrentPage;
            var currentID   = currentPage != null ? currentPage.ID : 0;

            return(new HelperResult(w =>
            {
                using (var writer = new HtmlTextWriter(w))
                {
                    var pages = _web.CachingPages.Where(p => p.Locale.Equals(locale, StringComparison.OrdinalIgnoreCase));
                    //IEnumerable<WebPage> pages = null;

                    if (ismenu)
                    {
                        pages = pages.Where(p => p.ShowInMenu);
                    }

                    if (issitemap)
                    {
                        pages = pages.Where(p => p.ShowInSitemap);
                    }

                    pages = pages.OrderBy(p => p.Pos).ToList();

                    var topPages = dataType == 3 ? pages.Where(p => p.ParentID == currentPage.ID) : pages.Where(p => p.ParentID == 0);

                    if (dataType == 4 && currentPage != null)
                    {
                        if (currentPage.ParentID == 0)
                        {
                            topPages = pages.Where(p => p.ParentID == currentPage.ID);
                        }
                        else
                        {
                            topPages = pages.Where(p => !string.IsNullOrEmpty(p.Path) && p.Path.Equals(currentPage.Path, StringComparison.OrdinalIgnoreCase));
                        }
                    }

                    if (topPages.Count() == 0)
                    {
                        return;
                    }

                    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);

                    if (dataType == 3)
                    {
                        if (currentPage == null)
                        {
                            writer.WriteEndTag("ul");
                            return;
                        }
                        //pages = _web.Pages.Where(p => p.ParentID == currentPage.ID);
                    }

                    foreach (var p in topPages)
                    {
                        if (ismenu || issitemap)
                        {
                            if (!IsAccessibleToUser(p))
                            {
                                continue;
                            }
                        }

                        RenderNode(writer, p, pages, withAttributes, showimg, currentPage, dataType);
                    }

                    writer.WriteEndTag("ul");
                }
            }));
        }