Пример #1
0
        private void PerformCopy(N2.ContentItem newItem)
        {
            EnsureAuthorization(Permission.Write);
            EnsureAuthorization(Selection.MemorizedItem, Permission.Read);

            var persister = Engine.Persister;

            newItem = persister.Copy(newItem, Selection.SelectedItem);

            var security = Engine.SecurityManager;

            if (security.GetPermissions(User, newItem) != security.GetPermissions(User, Selection.SelectedItem))
            {
                security.CopyPermissions(newItem.Parent, newItem);
                persister.Repository.SaveOrUpdate(newItem);
            }
            if (newItem.IsPublished() && !security.IsAuthorized(User, newItem, Permission.Publish))
            {
                newItem.Published = null;
                persister.Repository.SaveOrUpdate(newItem);
            }
            Engine.AddActivity(new ManagementActivity {
                Operation = "Copy", PerformedBy = User.Identity.Name, Path = newItem.Path, ID = newItem.ID
            });

            Refresh(newItem, ToolbarArea.Both);
        }
Пример #2
0
        public TemplateDefinition GetTemplate(N2.ContentItem item)
        {
            var httpContext = httpContextProvider.Get();

            if (httpContext != null)
            {
                if (N2.Web.Mvc.Html.RegistrationExtensions.GetRegistrationExpression(httpContext) != null)
                {
                    return(null);
                }
            }

            string templateKey = item.TemplateKey;

            if (templateKey == null)
            {
                return(null);
            }

            return(GetTemplates(item.GetContentType()).Where(t => t.Name == templateKey).Select(t =>
            {
                t.OriginalFactory = t.TemplateFactory;
                t.TemplateFactory = () => item;
                return t;
            }).FirstOrDefault());
        }
Пример #3
0
    public override bool UpdateItem(N2.ContentItem item, Control editor)
    {
        RadioButtonList rbl    = editor as RadioButtonList;
        string          itemID = rbl.SelectedValue;

        item[this.Name] = itemID;
        return(true);
    }
        public override bool UpdateItem(N2.ContentItem item, Control editor)
        {
            var rbl = editor as RadioButtonList;
            var tf  = Convert.ToBoolean(rbl.SelectedValue);

            item[this.Name] = tf;

            return(true);
        }
        public StringBuilder GetXml(N2.ContentItem rootItem)
        {
            StringBuilder sb = new StringBuilder();

            using (System.IO.StringWriter sw = new System.IO.StringWriter(sb))
            {
                Write(rootItem, sw);
            }
            return(sb);
        }
Пример #6
0
        public override bool Match(N2.ContentItem item)
        {
            if (existing.ContainsKey(item.ID))
            {
                return(false);
            }

            existing.Add(item.ID, true);
            return(true);
        }
 protected virtual void OnWritingChildren(N2.ContentItem item, XmlTextWriter xtw)
 {
     xtw.WriteStartElement("children");
     if (IncludeChildren)
     {
         foreach (ContentItem child in GetChildren(item))
         {
             OnWritingItem(child, xtw);
         }
     }
     xtw.WriteEndElement();
 }
        protected virtual void OnWritingItem(N2.ContentItem item, XmlTextWriter xtw)
        {
            xtw.WriteStartElement("item");
            OnWritingDefaultAttributes(item, xtw);

            OnWritingAuthorizedRoles(item, xtw);
            OnWritingDetails(item, xtw);
            OnWritingDetailCollections(item, xtw);
            OnWritingChildren(item, xtw);

            xtw.WriteEndElement();
        }
Пример #9
0
    public override void UpdateEditor(N2.ContentItem item, Control editor)
    {
        RadioButtonList rbl = editor as RadioButtonList;

        if (rbl != null)
        {
            rbl.SelectedValue = item[this.Name].ToString();
            if (rbl.Items.FindByValue(item[this.Name].ToString()) != null)
            {
                rbl.Items.FindByValue(item[this.Name].ToString()).Selected = true;
            }
        }
    }
Пример #10
0
    public override void UpdateEditor(N2.ContentItem item, Control editor)
    {
        CheckBoxList lst = editor as CheckBoxList;

        if (lst != null)
        {
            foreach (ListItem li in lst.Items)
            {
                if (item[this.Name].ToString().Contains(li.Value))
                {
                    li.Selected = true;
                }
            }
        }
    }
Пример #11
0
    public override bool UpdateItem(N2.ContentItem item, Control editor)
    {
        CheckBoxList lst   = editor as CheckBoxList;
        ArrayList    items = new ArrayList();

        foreach (ListItem li in lst.Items)
        {
            if (li.Selected)
            {
                items.Add(li.Value);
            }
        }
        string[] itemID = (string[])items.ToArray(typeof(string));
        item[this.Name] = String.Join(",", itemID);
        return(true);
    }
Пример #12
0
        public TemplateDefinition GetTemplate(N2.ContentItem item)
        {
            string templateName = item["TemplateName"] as string;

            if (templateName == null)
            {
                return(null);
            }

            return(GetTemplates(item.GetContentType()).Where(t => t.Name == templateName).Select(t =>
            {
                t.Original = t.Template;
                t.Template = item;
                return t;
            }).FirstOrDefault());
        }
 protected virtual void OnWritingDefaultAttributes(N2.ContentItem item, XmlTextWriter xtw)
 {
     xtw.WriteAttributeString("id", item.ID.ToString());
     xtw.WriteAttributeString("name", item.Name);
     xtw.WriteAttributeString("title", item.Title);
     xtw.WriteAttributeString("zoneName", item.ZoneName);
     xtw.WriteAttributeString("created", GetDateTimeString(item.Created));
     xtw.WriteAttributeString("updated", GetDateTimeString(item.Updated));
     xtw.WriteAttributeString("published", (item.Published.HasValue) ? GetDateTimeString(item.Published.Value) : string.Empty);
     xtw.WriteAttributeString("expires", (item.Expires.HasValue) ? GetDateTimeString(item.Expires.Value) : string.Empty);
     xtw.WriteAttributeString("sortOrder", item.SortOrder.ToString());
     xtw.WriteAttributeString("url", engine.UrlParser.BuildUrl(item));
     xtw.WriteAttributeString("visible", item.Visible.ToString());
     xtw.WriteAttributeString("savedBy", item.SavedBy);
     xtw.WriteAttributeString("typeName", SerializationUtility.GetTypeAndAssemblyName(item.GetContentType()));
     xtw.WriteAttributeString("discriminator", engine.Definitions.GetDefinition(item).Discriminator);
 }
        public void Write(N2.ContentItem rootItem, System.IO.TextWriter output)
        {
            XmlTextWriter xtw = new XmlTextWriter(output);

            xtw.Formatting = this.XmlFormatting;
            xtw.WriteStartDocument();

            xtw.WriteStartElement("n2");
            xtw.WriteAttributeString("version", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());
            xtw.WriteAttributeString("exportVersion", "1");
            xtw.WriteAttributeString("exportDate", GetDateTimeString(N2.Utility.CurrentTime()));

            OnWritingItem(rootItem, xtw);

            xtw.WriteEndElement();
            xtw.WriteEndDocument();
        }
        public override bool UpdateItem(N2.ContentItem item, Control editor)
        {
            var themeEditors = GetThemeEditors(editor);

            foreach (var themeEditor in themeEditors)
            {
                themeEditor.UpdateObject(new CommandContext(themeEditor.Definition,
                                                            themeEditor.CurrentItem,
                                                            "theme-editor",
                                                            N2.Context.Current.RequestContext.User));
            }

            global::Cassette.Aspnet.CassetteHttpModule.Host.RequestContainer.Resolve <IBundleCacheRebuilder>()
            .RebuildCache();

            return(true);
        }
Пример #16
0
        protected void gvHistory_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            ContentItem currentVersion = Selection.SelectedItem;
            int         id             = Convert.ToInt32(e.CommandArgument);

            if (e.CommandName == "Publish")
            {
                if (currentVersion.ID == id)
                {
                    currentVersion.SavedBy = User.Identity.Name;
                    if (!currentVersion.Published.HasValue || currentVersion.Published.Value > Utility.CurrentTime())
                    {
                        currentVersion.Published = DateTime.Now;
                    }
                    Engine.Resolve <StateChanger>().ChangeTo(currentVersion, ContentState.Published);
                    persister.Save(currentVersion);
                    Refresh(currentVersion, ToolbarArea.Both);
                }
                else
                {
                    N2.ContentItem versionToRestore   = Engine.Persister.Get(id);
                    bool           storeCurrent       = versionToRestore.State == ContentState.Unpublished;
                    ContentItem    unpublishedVersion = versioner.ReplaceVersion(currentVersion, versionToRestore, storeCurrent);

                    currentVersion.SavedBy = User.Identity.Name;

                    if (!currentVersion.Published.HasValue || currentVersion.Published.Value > Utility.CurrentTime())
                    {
                        currentVersion.Published = DateTime.Now;
                    }
                    if (storeCurrent)
                    {
                        currentVersion.VersionIndex = versioner.GetVersionsOf(currentVersion).Max(v => v.VersionIndex) + 1;
                    }
                    Engine.Resolve <StateChanger>().ChangeTo(currentVersion, ContentState.Published);
                    persister.Save(currentVersion);
                    Refresh(currentVersion, ToolbarArea.Both);
                }
            }
            else if (currentVersion.ID != id && e.CommandName == "Delete")
            {
                ContentItem item = Engine.Persister.Get(id);
                persister.Delete(item);
            }
        }
Пример #17
0
        public override void RenderTemplate(System.Web.Mvc.HtmlHelper html, N2.ContentItem model)
        {
            var wrap = !model.IsPage && Defaults.IsContainerWrappable(model.ZoneName);

            if (wrap)
            {
                wrap = model.GetDetail("UseContainer", true);
            }

            if (wrap)
            {
                html.ViewContext.Writer.WriteLine("<div class=\"container\">");
            }
            base.RenderTemplate(html, model);
            if (wrap)
            {
                html.ViewContext.Writer.WriteLine("</div>");
            }
        }
Пример #18
0
        /// <summary>
        /// Get's the <see cref="ISitesSource"/> provider for the given <see cref="ContentItem"/>.
        /// </summary>
        /// <param name="contentItem"></param>
        /// <returns></returns>
        static ISitesSource GetSitesSource(ContentItem contentItem)
        {
            if (contentItem == null)
            {
                return(Find.StartPage as ISitesSource);
            }

            N2.ContentItem currentItem = contentItem;
            do
            {
                ISitesSource result = currentItem as ISitesSource;
                if (result != null)
                {
                    return(result);
                }

                currentItem = currentItem.Parent;
            } while (currentItem.Parent != null);

            return(Find.StartPage as ISitesSource);
        }
Пример #19
0
 protected override void OnInit(EventArgs args)
 {
     try
     {
         N2.ContentItem page = N2.Templates.Find.StartPage.NotFoundPage;
         if (page != null)
         {
             var wc = N2.Context.Current.Resolve <N2.Web.IWebContext>();
             wc.CurrentPage = page;
             Server.Execute(Url.Parse(page.FindPath(PathData.DefaultAction).RewrittenUrl).AppendQuery("postback", page.Url));
             Response.Status = "404 Not Found";
             Response.End();
             return;
         }
     }
     catch
     {
     }
     Response.Status = "404 Not Found";
     Response.Write("<html><body><h1>404 Not Found</h1></body></html>");
     Response.End();
 }
Пример #20
0
 protected override void OnInit(EventArgs args)
 {
     Response.Status = "500 Internal Server Error";
     try
     {
         N2.ContentItem page = N2.Templates.Find.StartPage.ErrorPage;
         if (page != null)
         {
             var wc = N2.Context.Current.Resolve <N2.Web.IWebContext>();
             wc.CurrentPage = page;
             Server.Execute(Url.Parse(page.FindPath(PathData.DefaultAction).RewrittenUrl).AppendQuery("postback", page.Url));
             Response.End();
             return;
         }
     }
     catch (Exception ex)
     {
         Trace.Write(ex.ToString());
     }
     Response.Write("<html><body><h1>500 Internal Server Error</h1></body></html>");
     Response.End();
 }
Пример #21
0
        private void PerformCopy(N2.ContentItem newItem)
        {
            var authorizationToWrite = Permission.Write;

            //Limit non-admins from copy/paste items in uploads folder
            if ((Selection.MemorizedItem.GetType() == typeof(FileSystem.Items.Directory) || Selection.MemorizedItem.GetType() == typeof(FileSystem.Items.File)) &&
                Selection.MemorizedItem.ID == 0)
            {
                var config = new ConfigurationManagerWrapper();
                authorizationToWrite = config.Sections.Management.UploadFolders.RequiredPermissionToModify;
            }

            EnsureAuthorization(authorizationToWrite);
            EnsureAuthorization(Selection.MemorizedItem, Permission.Read);

            var persister = Engine.Persister;

            newItem = persister.Copy(newItem, Selection.SelectedItem);

            var security = Engine.SecurityManager;

            if (security.GetPermissions(User, newItem) != security.GetPermissions(User, Selection.SelectedItem))
            {
                security.CopyPermissions(newItem.Parent, newItem);
                persister.Repository.SaveOrUpdate(newItem);
            }
            if (newItem.IsPublished() && !security.IsAuthorized(User, newItem, Permission.Publish))
            {
                newItem.Published = null;
                persister.Repository.SaveOrUpdate(newItem);
            }
            Engine.AddActivity(new ManagementActivity {
                Operation = "Copy", PerformedBy = User.Identity.Name, Path = newItem.Path, ID = newItem.ID
            });

            Refresh(newItem, ToolbarArea.Both);
        }
Пример #22
0
        private void PerformCopy(N2.ContentItem newItem)
        {
            EnsureAuthorization(Permission.Write);
            EnsureAuthorization(Selection.MemorizedItem, Permission.Read);

            var persister = Engine.Persister;

            newItem = persister.Copy(newItem, Selection.SelectedItem);

            var security = Engine.SecurityManager;

            if (security.GetPermissions(User, newItem) != security.GetPermissions(User, Selection.SelectedItem))
            {
                security.CopyPermissions(newItem.Parent, newItem);
                persister.Repository.Save(newItem);
            }
            if (newItem.IsPublished() && !security.IsAuthorized(User, newItem, Permission.Publish))
            {
                newItem.Published = null;
                persister.Repository.Save(newItem);
            }

            Refresh(newItem, ToolbarArea.Both);
        }
Пример #23
0
        protected void OnCopyClick(object sender, EventArgs e)
        {
            try
            {
                pnlNewName.Visible = false;
                N2.ContentItem newItem = Selection.MemorizedItem.Clone(true);
                newItem.Name = txtNewName.Text;

                PerformCopy(newItem);
            }
            catch (N2.Integrity.NameOccupiedException ex)
            {
                this.pnlNewName.Visible = true;
                SetErrorMessage(this.cvCopy, ex);
            }
            catch (N2.Definitions.NotAllowedParentException ex)
            {
                SetErrorMessage(this.cvCopy, ex);
            }
            catch (Exception ex)
            {
                SetErrorMessage(this.cvCopy, ex);
            }
        }
 public override bool IsProvidedBy(N2.ContentItem item)
 {
     return(item.VersionOf.HasValue);
 }
Пример #25
0
 public override bool IsProvidedBy(N2.ContentItem item)
 {
     return(base.IsProvidedBy(item) && !(item is RootDirectory));
 }
Пример #26
0
        static string GetPreferredUrl(N2.ContentItem contentItem, Uri requestBaseUri, bool cacheResult = true)
        {
            //
            // Pre-conditions

            if (contentItem == null)
            {
                return(string.Empty);
            }
            if (!contentItem.IsPage)
            {
                return(contentItem.Url);
            }

            //
            // Determine base-url/authority from sites source and requested URL.

            HttpContext httpContext = HttpContext.Current;
            HttpRequest request     = httpContext.Request;

            N2.Web.ISitesSource       sitesSource = GetSitesSource(contentItem);
            IEnumerable <N2.Web.Site> sites       = sitesSource.GetSites();

            N2.Web.Site site = sites             // Try to match domain, otherwise default to first-available authority
                               .Where(s =>
                                      s.Authority.Equals(request.Url.Authority, StringComparison.OrdinalIgnoreCase))
                               .FirstOrDefault()
                               ?? sites.FirstOrDefault();

            Uri siteBaseUrl = (site != null)             // "Safe" URLs are fully qualified
                                ? new Uri(string.Format("{0}{1}{2}", request.Url.Scheme, Uri.SchemeDelimiter, site.Authority))
                                : requestBaseUri;

            //
            // Check cache

            System.Web.Caching.Cache cache = httpContext.Cache;
            cacheResult = cacheResult && cache != null;
            string cacheKey = null;

            if (cacheResult)
            {
                cacheKey = string.Format(
                    "RequestLifeCycleHandler.PreferredUrl_{0}{1}{2}{3}",
                    contentItem.ID,
                    contentItem.Updated.Ticks,
                    contentItem.State,                     // forces re-calc when a page is published
                    siteBaseUrl);
                string cachedResult = cache[cacheKey] as string;
                if (!string.IsNullOrEmpty(cachedResult))
                {
                    return(cachedResult);
                }
            }

            //
            // Not in cache, calc result

            var    parent = contentItem.Parent ?? contentItem.VersionOf.Parent;
            string result;

            if ((parent == null) || (parent == Find.RootItem))
            {
                result = siteBaseUrl.ToString();                 // contentItem.Url.ToUri(siteBaseUrl).ToString();
            }
            else
            {
                result = new Uri(
                    siteBaseUrl,
                    contentItem.Url).ToString();
            }

            //
            // Cache result

            if (cacheResult)
            {
                cache[cacheKey] = result;
            }

            return(result);
        }
Пример #27
0
        public override IDictionary <string, System.Web.UI.Control> AddDefinedEditors(ItemDefinition definition, N2.ContentItem item, System.Web.UI.Control container, System.Security.Principal.IPrincipal user, Type containerTypeFilter, IEnumerable <string> editableNameFilter)
        {
            ItemDefinition cloned = null;

            // add a "wrap in container" checkbox to all parts that are within zones that are not wrapped in a container (BeforeMain, AfterMain).
            if (!definition.IsPage)
            {
                if (!(Defaults.IsContainerWrappable(item.ZoneName) ||
                      Defaults.IsContainerWrappable(System.Web.HttpContext.Current.Request["zoneName"])))
                {
                    cloned = definition.Clone();
                    var isWrappable = cloned.Editables.FirstOrDefault(x => x.Name == "UseContainer");
                    if (isWrappable != null)
                    {
                        cloned.Editables.Remove(isWrappable);
                    }
                }
            }

            if (item is IItemAdapter)
            {
                var result = (item as IItemAdapter).AddDefinedEditors(cloned ?? definition, container, user, containerTypeFilter, editableNameFilter);
                if (result != null)
                {
                    return(result);
                }
            }
            return(base.AddDefinedEditors(cloned ?? definition, item, container, user, containerTypeFilter, editableNameFilter));
        }
 public override void UpdateEditor(N2.ContentItem item, Control editor)
 {
 }