示例#1
0
        public override Guid AddWebpage(Webpage webpage)
        {
            // add main entry
            webpage.WebpageID = Guid.NewGuid();

            SqlConnection connection = new SqlConnection(this._connectionString);

            string sql = @"
            INSERT INTO
            purple_Webpages
            (WebpageID, ParentID, Title, MenuTitle)
            VALUES
            (@WebpageID, @ParentID, Title, MenuTitle);";

            SqlCommand command = new SqlCommand(sql, connection);
            command.Parameters.Add("@WebpageID", SqlDbType.UniqueIdentifier).Value = webpage.WebpageID;
            command.Parameters.Add("@ParentID", SqlDbType.UniqueIdentifier).Value = webpage.ParentID;
            command.Parameters.Add("@Title", SqlDbType.NVarChar).Value = webpage.Title;
            command.Parameters.Add("@MenuTitle", SqlDbType.NVarChar).Value = webpage.MenuTitle;

            connection.Open();
            command.ExecuteNonQuery();
            connection.Close();

            // add to revision
            UpdateWebpage(webpage);

            return webpage.WebpageID;
        }
示例#2
0
        public static void UpdateWebpage(Webpage webpage)
        {
            webpage.RevisedDate = DateTime.Now;
            webpage.RevisedByUsername = (HttpContext.Current != null && HttpContext.Current.User.Identity.IsAuthenticated) ? HttpContext.Current.User.Identity.Name : "";

            PurpleDataProviderManager.Provider.UpdateWebpage(webpage);

            ReloadPages();
        }
示例#3
0
        public static Guid AddWebpage(Webpage webpage)
        {
            webpage.IsPublished = true;
            webpage.RevisedDate = DateTime.Now;
            webpage.RevisedByUsername = (HttpContext.Current != null && HttpContext.Current.User.Identity.IsAuthenticated) ? HttpContext.Current.User.Identity.Name : "";

            PurpleDataProviderManager.Provider.AddWebpage(webpage);

            ReloadPages();

            return webpage.WebpageID;
        }
示例#4
0
        public override Guid AddWebpage(Webpage webpage)
        {
            // check for existing URL
            GetWebpageUrls();
            if (_webpagesUrlDictionary.ContainsKey(webpage.Url))
                throw new Exception(string.Format("Page with URL '{0}' already exists", webpage.Url));

            webpage.WebpageID = Guid.NewGuid();

            // add to main listing
            XmlDocument doc = LoadXml("pages.xml");
            XmlNode pageNode = doc.CreateNode(XmlNodeType.Element, "page", "");

            XmlAttribute webpageid = doc.CreateAttribute("webpageid");
            webpageid.Value = webpage.WebpageID.ToString();
            pageNode.Attributes.Append(webpageid);

            XmlAttribute parentwebpageid = doc.CreateAttribute("parentid");
            parentwebpageid.Value = webpage.ParentID.ToString();
            pageNode.Attributes.Append(parentwebpageid);

            XmlAttribute url = doc.CreateAttribute("url");
            url.Value = webpage.Url.ToString();
            pageNode.Attributes.Append(url);

            XmlAttribute title = doc.CreateAttribute("title");
            title.Value = webpage.Title.ToString();
            pageNode.Attributes.Append(title);

            XmlAttribute menuTitle = doc.CreateAttribute("menutitle");
            menuTitle.Value = webpage.MenuTitle.ToString();
            pageNode.Attributes.Append(menuTitle);

            doc.SelectSingleNode("//pages").AppendChild(pageNode);
            doc.Save(Path.Combine(System.Web.HttpContext.Current.Server.MapPath(_basePath), "pages.xml"));

            // creat the new page
            FileStream fileStream = new FileStream(
                    Path.Combine(System.Web.HttpContext.Current.Server.MapPath(_basePath), webpage.WebpageID.ToString() + ".xml"),
                    FileMode.Create);

            CreateWebpageXml(webpage, fileStream);
            fileStream.Close();

            return webpage.WebpageID;
        }
示例#5
0
        public override Webpage CreateWebpage(RequestContext requestContext)
        {
            string newsid = requestContext.RouteData.Values["newsid"] as string;

            // look up news item
            // NewsItem newsItem = NewsItems.FindNewsItem(newsid);

            // construct page for
            Webpage webpage = new Webpage();
            webpage.Title = "Some news";

            if (string.IsNullOrEmpty(newsid))
            {
                webpage.Areas.Add(new WebpageArea() { ContentHtml = "<h2>News page</h2><p>This is what happens with nothing in the URL.</p>" });
            }
            else
            {
                webpage.Areas.Add(new WebpageArea() { ContentHtml = "<h2>News page</h2><h3>News Itesm: " + newsid + "</h3><p>Blah blah</p>" });
            }

            return webpage;
        }
示例#6
0
 public abstract Guid AddWebpage(Webpage webpage);
示例#7
0
        private Webpage CreateWebpageFromDataReader(SqlDataReader reader)
        {
            Webpage webpage = new Webpage();

            webpage.WebpageID = new Guid(reader["WebpageID"].ToString());
            webpage.ParentID = new Guid(reader["ParentID"].ToString());
            webpage.RevisionID = new Guid(reader["RevisionID"].ToString());
            webpage.Title = reader["Title"].ToString();
            webpage.MenuTitle = reader["MenuTitle"].ToString();
            webpage.Url = reader["Url"].ToString();
            webpage.Filename = reader["Filename"].ToString();
            webpage.MasterPageFilename = reader["MasterPageFilename"].ToString();
            webpage.MetaDescription = reader["MetaDescription"].ToString();
            webpage.MetaKeywords = reader["MetaKeywords"].ToString();
            webpage.ForceSsl = (bool)reader["ForceSsl"];
            webpage.ShowInMenu = (bool)reader["ShowInMenu"];
            webpage.MenuType = (MenuType)(int)reader["MenuType"];
            webpage.SortOrder = (int)reader["SortOrder"];
            webpage.FullUrl = (string)reader["FullUrl"];
            webpage.Editors = (string)reader["Editors"];

            webpage.RevisedByUsername = (string)reader["RevisedByUsername"];
            webpage.RevisedDate = (DateTime)reader["RevisedDate"];

            return webpage;
        }
示例#8
0
        private void GetWebpageAreas(SqlConnection connection, Webpage webpage)
        {
            string sql = @"
            SELECT
            *
            FROM
            purple_WebpageAreas
            WHERE
            RevisionID = @RevisionID;";

            SqlCommand command = new SqlCommand(sql, connection);
            command.Parameters.Add("@RevisionID", SqlDbType.UniqueIdentifier).Value = webpage.RevisionID;

            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                WebpageArea area = new WebpageArea();

                area.AreaID = new Guid(reader["AreaID"].ToString());
                area.WebpageID = webpage.WebpageID;
                area.RevisionID = webpage.RevisionID;
                area.SortOrder = (int)reader["SortOrder"];
                area.ContentPlaceHolderID = (string)reader["ContentPlaceHolderID"];
                area.ContentHtml = (string)reader["ContentHtml"];
                area.ControlName = (string)reader["ControlName"];

                webpage.Areas.Add(area);
            }
        }
示例#9
0
        public override void UpdateWebpage(Webpage webpage)
        {
            webpage.RevisionID = Guid.NewGuid();

            SqlConnection connection = new SqlConnection(this._connectionString);

            string sql = @"
            INSERT INTO
            purple_WebpageRevisions
            (WebpageID, ParentID, RevisionID, Title, MenuTitle, MetaDescription, MetaKeywords, ForceSsl, IsPublished, Filename, Url, MasterPageFilename, FullUrl, MenuType, SortOrder, ShowInMenu, RevisedByUsername, RevisedDate, Editors)
            VALUES
            (@WebpageID, @ParentID, @RevisionID, @Title, @MenuTitle, @MetaDescription, @MetaKeywords, @ForceSsl, @IsPublished, @Filename, @Url, @MasterPageFilename, @FullUrl, @MenuType, @SortOrder, @ShowInMenu, @RevisedByUsername, @RevisedDate, @Editors);

            UPDATE
            purple_Webpages
            SET
            Title = @Title, MenuTitle=@MenuTitle
            WHERE
            WebpageID = @WebpageID;
            ";

            SqlCommand command = new SqlCommand(sql, connection);
            command.Parameters.Add("@WebpageID", SqlDbType.UniqueIdentifier).Value = webpage.WebpageID;
            command.Parameters.Add("@ParentID", SqlDbType.UniqueIdentifier).Value = webpage.ParentID;
            command.Parameters.Add("@RevisionID", SqlDbType.UniqueIdentifier).Value = webpage.RevisionID;
            command.Parameters.Add("@Title", SqlDbType.NVarChar).Value = webpage.Title;
            command.Parameters.Add("@MenuTitle", SqlDbType.NVarChar).Value = webpage.MenuTitle;
            command.Parameters.Add("@MetaDescription", SqlDbType.NVarChar).Value = webpage.MetaDescription;
            command.Parameters.Add("@MetaKeywords", SqlDbType.NVarChar).Value = webpage.MetaKeywords;
            command.Parameters.Add("@ForceSsl", SqlDbType.Bit).Value = webpage.ForceSsl;
            command.Parameters.Add("@IsPublished", SqlDbType.Bit).Value = webpage.IsPublished;
            command.Parameters.Add("@Filename", SqlDbType.NVarChar).Value = webpage.Filename;
            command.Parameters.Add("@Url", SqlDbType.NVarChar).Value = webpage.Url;
            command.Parameters.Add("@MasterPageFilename", SqlDbType.NVarChar).Value = webpage.MasterPageFilename;

            command.Parameters.Add("@FullUrl", SqlDbType.NVarChar).Value = webpage.FullUrl;
            command.Parameters.Add("@MenuType", SqlDbType.Int).Value = (int) webpage.MenuType;
            command.Parameters.Add("@SortOrder", SqlDbType.Int).Value = webpage.SortOrder;
            command.Parameters.Add("@ShowInMenu", SqlDbType.Bit).Value = webpage.ShowInMenu;

            command.Parameters.Add("@RevisedByUsername", SqlDbType.NVarChar).Value = webpage.RevisedByUsername;
            command.Parameters.Add("@RevisedDate", SqlDbType.DateTime).Value = webpage.RevisedDate;

            command.Parameters.Add("@Editors", SqlDbType.NVarChar).Value = webpage.Editors;

            connection.Open();
            command.ExecuteNonQuery();

            // add areas
            foreach (WebpageArea area in webpage.Areas)
            {
                area.AreaID = Guid.NewGuid();

                sql = @"
            INSERT INTO
            purple_WebpageAreas
            (AreaID, WebpageID, RevisionID, ContentPlaceHolderID, SortOrder, ControlName, ContentHtml)
            VALUES
            (@AreaID, @WebpageID, @RevisionID, @ContentPlaceHolderID, @SortOrder, @ControlName, @ContentHtml);";

                command = new SqlCommand(sql, connection);
                command.Parameters.Add("@AreaID", SqlDbType.UniqueIdentifier).Value = area.AreaID;
                command.Parameters.Add("@WebpageID", SqlDbType.UniqueIdentifier).Value = webpage.WebpageID;
                command.Parameters.Add("@RevisionID", SqlDbType.UniqueIdentifier).Value = webpage.RevisionID;
                command.Parameters.Add("@ContentPlaceHolderID", SqlDbType.NVarChar).Value = area.ContentPlaceHolderID;
                command.Parameters.Add("@SortOrder", SqlDbType.NVarChar).Value = area.SortOrder;
                command.Parameters.Add("@ControlName", SqlDbType.NVarChar).Value = area.ControlName;
                command.Parameters.Add("@ContentHtml", SqlDbType.NText).Value = area.ContentHtml;

                command.ExecuteNonQuery();
            }

            connection.Close();
            command.Dispose();
        }
示例#10
0
        public override Webpage GetPublishedWebpage(Guid webpageID)
        {
            Webpage webpage = null;

            // refresh index
            if (_webpagesUrlDictionary == null)
                GetWebpageUrls();

            XmlDocument doc = LoadXml("" + webpageID.ToString() + ".xml");
            if (doc != null && _webpagesIDDictionary != null)
            {
                WebpageUrlInfo urlInfo = _webpagesIDDictionary[webpageID];

                webpage = new Webpage();
                webpage.WebpageID = webpageID;
                webpage.IsSiteRoot = (webpageID == Guid.Empty);
                webpage.ParentID = urlInfo.ParentID;
                webpage.Url = urlInfo.Url;

                XmlNode revisionNode = doc.SelectSingleNode("//revision[@ispublished='true']");

                if (revisionNode == null)
                    revisionNode = doc.SelectNodes("//revision")[0];

                ProcessRevisionXml(revisionNode, webpage);
            }

            return webpage;
        }
示例#11
0
        private void ProcessRevisionXml(XmlNode node, Webpage webpage)
        {
            webpage.RevisionID = GetAttributeGuid(node, "revisionid", Guid.Empty);
            webpage.IsPublished = GetAttributeBool(node, "ispublished", false);
            webpage.RevisedDate = GetAttributeDateTime(node, "reviseddate", DateTime.MinValue);
            webpage.RevisedByUsername = GetAttributeString(node, "revisedbyusername", "");

            webpage.Title = GetSubNodeString(node, "meta/title", "");
            webpage.MenuTitle = GetSubNodeString(node, "meta/menutitle", "");
            webpage.MetaDescription = GetSubNodeString(node, "meta/metadescription", "");
            webpage.MetaKeywords = GetSubNodeString(node, "meta/metakeywords", "");
            webpage.Filename = GetSubNodeString(node, "meta/filename", "");
            webpage.MasterPageFilename = GetSubNodeString(node, "meta/masterpagefilename", "");
            webpage.ForceSsl = GetSubNodeBoolean(node, "meta/forcessl", false);
            webpage.ShowInMenu = GetSubNodeBoolean(node, "meta/showinmenu", true);
            webpage.SortOrder = GetSubNodeInt(node, "meta/sortorder", 0);
            webpage.MenuType = (MenuType) GetSubNodeInt(node, "meta/menutype", 0);
            webpage.FullUrl = GetSubNodeString(node, "meta/fullurl", "");
            webpage.Editors = GetSubNodeString(node, "meta/editors", "");

            webpage.ContentExpirationDate = GetSubNodeDateTime(node, "meta/contentexpirationdate", DateTime.MinValue);
            webpage.CommonAreaHeader = GetSubNodeString(node, "meta/commonareaheader", "");
            webpage.IgnoreParentHeader = GetSubNodeBoolean(node, "meta/IgnoreParentHeader", false);

            // process areas
            XmlNodeList areaNodes = node.SelectNodes("areas/area");
            foreach (XmlNode areaNode in areaNodes)
            {
                WebpageArea area = new WebpageArea();
                area.WebpageID = webpage.WebpageID;

                area.ContentPlaceHolderID = GetAttributeString(areaNode, "contentplaceholderid", "");
                area.ControlName = GetAttributeString(areaNode, "controlname", "");
                area.SortOrder = GetAttributeInt(areaNode, "sortoder", 9999);
                area.ContentHtml = areaNode.InnerText;

                webpage.Areas.Add(area);
            }
        }
示例#12
0
        public override void UpdateWebpage(Webpage webpage)
        {
            webpage.RevisionID = Guid.NewGuid();

            SqlConnection connection = new SqlConnection(this._connectionString);

            string sql = @"
INSERT INTO 
	purple_WebpageRevisions
		(WebpageID, ParentID, RevisionID, Title, MenuTitle, MetaDescription, MetaKeywords, ForceSsl, IsPublished, Filename, Url, MasterPageFilename, FullUrl, MenuType, SortOrder, ShowInMenu, RevisedByUsername, RevisedDate, Editors)
VALUES
		(@WebpageID, @ParentID, @RevisionID, @Title, @MenuTitle, @MetaDescription, @MetaKeywords, @ForceSsl, @IsPublished, @Filename, @Url, @MasterPageFilename, @FullUrl, @MenuType, @SortOrder, @ShowInMenu, @RevisedByUsername, @RevisedDate, @Editors);

UPDATE 
	purple_Webpages
SET 
	Title = @Title, MenuTitle=@MenuTitle
WHERE
	WebpageID = @WebpageID;
";

            SqlCommand command = new SqlCommand(sql, connection);

            command.Parameters.Add("@WebpageID", SqlDbType.UniqueIdentifier).Value  = webpage.WebpageID;
            command.Parameters.Add("@ParentID", SqlDbType.UniqueIdentifier).Value   = webpage.ParentID;
            command.Parameters.Add("@RevisionID", SqlDbType.UniqueIdentifier).Value = webpage.RevisionID;
            command.Parameters.Add("@Title", SqlDbType.NVarChar).Value              = webpage.Title;
            command.Parameters.Add("@MenuTitle", SqlDbType.NVarChar).Value          = webpage.MenuTitle;
            command.Parameters.Add("@MetaDescription", SqlDbType.NVarChar).Value    = webpage.MetaDescription;
            command.Parameters.Add("@MetaKeywords", SqlDbType.NVarChar).Value       = webpage.MetaKeywords;
            command.Parameters.Add("@ForceSsl", SqlDbType.Bit).Value                = webpage.ForceSsl;
            command.Parameters.Add("@IsPublished", SqlDbType.Bit).Value             = webpage.IsPublished;
            command.Parameters.Add("@Filename", SqlDbType.NVarChar).Value           = webpage.Filename;
            command.Parameters.Add("@Url", SqlDbType.NVarChar).Value                = webpage.Url;
            command.Parameters.Add("@MasterPageFilename", SqlDbType.NVarChar).Value = webpage.MasterPageFilename;

            command.Parameters.Add("@FullUrl", SqlDbType.NVarChar).Value = webpage.FullUrl;
            command.Parameters.Add("@MenuType", SqlDbType.Int).Value     = (int)webpage.MenuType;
            command.Parameters.Add("@SortOrder", SqlDbType.Int).Value    = webpage.SortOrder;
            command.Parameters.Add("@ShowInMenu", SqlDbType.Bit).Value   = webpage.ShowInMenu;

            command.Parameters.Add("@RevisedByUsername", SqlDbType.NVarChar).Value = webpage.RevisedByUsername;
            command.Parameters.Add("@RevisedDate", SqlDbType.DateTime).Value       = webpage.RevisedDate;

            command.Parameters.Add("@Editors", SqlDbType.NVarChar).Value = webpage.Editors;

            connection.Open();
            command.ExecuteNonQuery();

            // add areas
            foreach (WebpageArea area in webpage.Areas)
            {
                area.AreaID = Guid.NewGuid();

                sql = @"
INSERT INTO 
	purple_WebpageAreas
		(AreaID, WebpageID, RevisionID, ContentPlaceHolderID, SortOrder, ControlName, ContentHtml)
VALUES
		(@AreaID, @WebpageID, @RevisionID, @ContentPlaceHolderID, @SortOrder, @ControlName, @ContentHtml);"        ;

                command = new SqlCommand(sql, connection);
                command.Parameters.Add("@AreaID", SqlDbType.UniqueIdentifier).Value       = area.AreaID;
                command.Parameters.Add("@WebpageID", SqlDbType.UniqueIdentifier).Value    = webpage.WebpageID;
                command.Parameters.Add("@RevisionID", SqlDbType.UniqueIdentifier).Value   = webpage.RevisionID;
                command.Parameters.Add("@ContentPlaceHolderID", SqlDbType.NVarChar).Value = area.ContentPlaceHolderID;
                command.Parameters.Add("@SortOrder", SqlDbType.NVarChar).Value            = area.SortOrder;
                command.Parameters.Add("@ControlName", SqlDbType.NVarChar).Value          = area.ControlName;
                command.Parameters.Add("@ContentHtml", SqlDbType.NText).Value             = area.ContentHtml;

                command.ExecuteNonQuery();
            }

            connection.Close();
            command.Dispose();
        }
示例#13
0
        void PurplePageSaveButton_Click(object sender, EventArgs e)
        {
            // What to do now?
            Webpage webpage = this.Webpage;

            FindAdminControls();

            // update main values
            webpage.Filename = webpageFilename.Text;
            webpage.FullUrl  = ((!webpage.Parent.IsSiteRoot) ? webpage.Parent.Url + "/" : "") + webpage.Filename;

            string url = webpageUrl.Text;

            // TODO: seriously need some better checking here
            webpage.Url = (!String.IsNullOrWhiteSpace(url)) ? url : webpage.FullUrl;

            webpage.Title              = webpagePageTitle.Text;
            webpage.MenuTitle          = webpageMenuTitle.Text;
            webpage.MetaDescription    = webpageMetaDescription.Text;
            webpage.MetaKeywords       = webpageMetaKeywords.Text;
            webpage.MasterPageFilename = webpageMasterPageFilename.SelectedValue + ".master";

            webpage.ForceSsl   = webpageForceSsl.Checked;
            webpage.ShowInMenu = webpageShowInMenu.Checked;


            webpage.CommonAreaHeader   = webpageCommonAreaHeader.Text;
            webpage.IgnoreParentHeader = webpageIgnoreParentHeader.Checked;
            DateTime expiresDate = DateTime.MinValue;

            if (DateTime.TryParse(webpageContentExpirationDate.Text, out expiresDate))
            {
                webpage.ContentExpirationDate = expiresDate;
            }
            else
            {
                webpage.ContentExpirationDate = DateTime.MinValue;
            }


            webpage.MenuType = (MenuType)Enum.Parse(typeof(MenuType), webpageMenuType.SelectedValue);

            int menuSortOrder = 0;

            if (Int32.TryParse(webpageSortOrder.Text, out menuSortOrder))
            {
                webpage.SortOrder = menuSortOrder;
            }

            // permissions
            List <string> pageEditors = new List <string>();

            foreach (ListItem li in webpageEditors.Items)
            {
                if (li.Selected)
                {
                    pageEditors.Add(li.Value);
                }
            }
            webpage.Editors = String.Join(",", pageEditors.ToArray());


            // update modules
            webpage.Areas.Clear();
            foreach (ContentPlaceHolder placeholder in ContentPlaceHolders)
            {
                int sortOrder = 1;
                // each sub control should be a editarea.ascx control
                foreach (Control control in placeholder.Controls)
                {
                    WebpageArea area = new WebpageArea();

                    string html = (control.FindControl("HtmlContent") as TextBox).Text;

                    area.ContentPlaceHolderID = placeholder.ID;
                    area.ContentHtml          = html;
                    DropDownList controlList = control.FindControl("ControlName") as DropDownList;
                    area.ControlName = (!String.IsNullOrWhiteSpace(controlList.SelectedValue)) ? controlList.SelectedValue + ".ascx" : "";
                    area.SortOrder   = sortOrder;

                    webpage.Areas.Add(area);
                    sortOrder++;
                }
            }

            // save
            webpage.IsPublished = true;
            Webpages.UpdateWebpage(webpage);

            // see the finished page
            Response.Redirect("/" + webpage.Url);
        }
示例#14
0
 public abstract void UpdateWebpage(Webpage webpage);
示例#15
0
        public override void UpdateWebpage(Webpage webpage)
        {
            webpage.IsPublished = true;

            // update the URL in the main index
            XmlDocument pagesDoc = LoadXml("pages.xml");
            XmlNode pageNode = pagesDoc.SelectSingleNode("//page[@webpageid='" + webpage.WebpageID.ToString() + "']");
            if (pageNode.Attributes["url"] != null) {
                pageNode.Attributes["url"].Value = webpage.Url;
            } else {
                XmlAttribute attr = pagesDoc.CreateAttribute("url");
                attr.Value = webpage.Url.ToString();
                pageNode.Attributes.Append(attr);
            }

            if (pageNode.Attributes["title"] != null)
            {
                pageNode.Attributes["title"].Value = webpage.Url;
            }
            else
            {
                XmlAttribute attr = pagesDoc.CreateAttribute("url");
                attr.Value = webpage.Url.ToString();
                pageNode.Attributes.Append(attr);
            }
            if (pageNode.Attributes["menutitle"] != null)
            {
                pageNode.Attributes["menutitle"].Value = webpage.Url;
            }
            else
            {
                XmlAttribute attr = pagesDoc.CreateAttribute("menutitle");
                attr.Value = webpage.MenuType.ToString();
                pageNode.Attributes.Append(attr);
            }
            SaveXml(pagesDoc, "pages.xml");

            // open existing document
            XmlDocument doc = LoadXml(webpage.WebpageID.ToString() + ".xml");

            // set all revisions to older
            if (webpage.IsPublished)
            {
                XmlNodeList revisions = doc.SelectNodes("//revision");
                foreach (XmlNode revision in revisions)
                {
                    revision.Attributes["ispublished"].Value = "false";
                }
            }

            // create new page
            webpage.RevisionID = Guid.NewGuid();
            MemoryStream stream = new MemoryStream();
            CreateWebpageXml(webpage, stream);

            // load as XML
            XmlDocument newpageDoc = new XmlDocument();
            stream.Seek(0, SeekOrigin.Begin);
            newpageDoc.Load(stream);
            stream.Close();

            // find the new revision
            XmlNode newRevision = newpageDoc.SelectSingleNode("//revision");
            newRevision = doc.ImportNode(newRevision, true);

            // add the new revision to the existing doc (at the top)
            doc.SelectSingleNode("//page").PrependChild(newRevision);

            // save to disk
            doc.Save(Path.Combine(System.Web.HttpContext.Current.Server.MapPath(_basePath), webpage.WebpageID.ToString() + ".xml"));
        }
示例#16
0
        public override List<Webpage> GetWebpageRevisions(Guid webpageID)
        {
            // refresh index
            if (_webpagesUrlDictionary == null)
                GetWebpageUrls();

            List<Webpage> revisions = new List<Webpage>();

            XmlDocument doc = LoadXml("" + webpageID.ToString() + ".xml");
            if (doc != null && _webpagesIDDictionary != null)
            {
                WebpageUrlInfo urlInfo = _webpagesIDDictionary[webpageID];

                XmlNodeList revisionNodes = doc.SelectNodes("//revision");

                foreach (XmlNode revisionNode in revisionNodes)
                {
                    Webpage webpage = new Webpage();
                    webpage.WebpageID = webpageID;
                    webpage.IsSiteRoot = (webpageID == Guid.Empty);
                    webpage.ParentID = urlInfo.ParentID;
                    webpage.Url = urlInfo.Url;

                    ProcessRevisionXml(revisionNode, webpage);

                    revisions.Add(webpage);
                }
            }

            return revisions;
        }
示例#17
0
        public override Webpage GetWebpage(Guid webpageID, Guid revisionID)
        {
            Webpage webpage = null;

            XmlDocument doc = LoadXml("" + webpageID.ToString() + ".xml");
            if (doc != null)
            {
                webpage = new Webpage();
                webpage.WebpageID = webpageID;
                webpage.IsSiteRoot = (webpageID == Guid.Empty);
                XmlNode revisionNode = doc.SelectSingleNode("//revision[@revisionid='" + revisionID.ToString() + "']");

                if (revisionNode != null)
                    ProcessRevisionXml(revisionNode, webpage);
                else
                    webpage = null;
            }

            return webpage;
        }
示例#18
0
        private void CreateWebpageXml(Webpage webpage, Stream stream)
        {
            // create new document
            XmlTextWriter writer = new XmlTextWriter(stream, Encoding.Unicode);
            writer.Formatting = Formatting.Indented;
            writer.WriteStartDocument();
            writer.WriteStartElement("page");

            writer.WriteStartElement("revision");
            writer.WriteAttributeString("revisionid", webpage.RevisionID.ToString());
            writer.WriteAttributeString("ispublished", webpage.IsPublished.ToString().ToLower());
            writer.WriteAttributeString("createdate", webpage.RevisedDate.ToUniversalTime().ToString());
            writer.WriteAttributeString("revisedbyusername", webpage.RevisedByUsername);

            writer.WriteStartElement("meta");
            writer.WriteElementString("title", webpage.Title);
            writer.WriteElementString("menutitle", webpage.MenuTitle);
            writer.WriteElementString("metadescription", webpage.MetaDescription);
            writer.WriteElementString("metakeywords", webpage.MetaKeywords);
            writer.WriteElementString("masterpagefilename", webpage.MasterPageFilename);
            writer.WriteElementString("filename", webpage.Filename);
            writer.WriteElementString("forcessl", webpage.ForceSsl.ToString().ToLower());
            writer.WriteElementString("showinmenu", webpage.ShowInMenu.ToString().ToLower());
            writer.WriteElementString("menutype", ((int)webpage.MenuType).ToString().ToLower());
            writer.WriteElementString("sortorder", webpage.SortOrder.ToString().ToLower());
            writer.WriteElementString("fullurl", webpage.FullUrl);
            writer.WriteElementString("editors", webpage.Editors);

            writer.WriteElementString("contentexpirationdate", webpage.ContentExpirationDate.ToUniversalTime().ToString());
            writer.WriteElementString("commonareaheader", webpage.CommonAreaHeader);
            writer.WriteElementString("ignoreparentheader", webpage.IgnoreParentHeader.ToString().ToLower());

            writer.WriteEndElement(); // meta

            writer.WriteStartElement("areas");
            foreach (WebpageArea area in webpage.Areas)
            {
                writer.WriteStartElement("area");
                writer.WriteAttributeString("contentplaceholderid", area.ContentPlaceHolderID);
                writer.WriteAttributeString("controlname", area.ControlName);

                string html = area.ContentHtml;
                // TEMP: TinyMCE adds CDATA tags which break XML
                html.Replace("<![CDATA[", "");
                html.Replace("]]>", "");

                if (!String.IsNullOrEmpty(html) )
                    writer.WriteCData(html);

                writer.WriteEndElement(); // areas
            }
            writer.WriteEndElement(); // areas

            writer.WriteEndElement(); // revision

            writer.WriteEndElement(); // page
            writer.WriteEndDocument();
            writer.Flush();
        }
示例#19
0
        protected override void OnInit(EventArgs e)
        {
            FormMode formMode = FormMode.Container;
            PageMode pageMode = PageMode.Render;

            // local variable
            Webpage webpage = this.Webpage;

            if ((Request.QueryString["pagemode"] + "").ToLower() == "edit")
            {
                pageMode = PageMode.Edit;
            }
            //else if (Request.QueryString["pagemode"] + "" == "newpage")
            //	pageMode = PageMode.NewPage;


            bool userHasPermissions = GetUserPermissions();

            if (!userHasPermissions)
            {
                pageMode = PageMode.Render;
            }


            // get and clear place holders
            ContentPlaceHolders = FindControls <ContentPlaceHolder>(this.Body);

            if (ContentPlaceHolders.Count == 0)
            {
                throw new Exception("The masterpage '{0}' has no <asp:Content runat=\"Server\" /> controls");
            }

            ContentPlaceHolders.ForEach(p => p.Controls.Clear());

            // update meta data
            this.Title           = webpage.Title + ((!webpage.IsSiteRoot) ? PurpleSettings.PageSuffix : string.Empty);
            this.MetaDescription = webpage.MetaDescription;
            this.MetaKeywords    = webpage.MetaKeywords;

            if (userHasPermissions)
            {
                HtmlLink adminStylesLink = new HtmlLink()
                {
                    Href = PurpleSettings.CmsPath + "assets/admincontrols/admin.css"
                };
                adminStylesLink.Attributes.Add("rel", "stylesheet");
                this.Header.Controls.Add(adminStylesLink);
            }


            if (pageMode == PageMode.Render)
            {
                // add the admin controls first so the form is already there
                if (userHasPermissions)
                {
                    AddFormToBody();

                    // add admin controls
                    AdminControl = LoadControl(PurpleSettings.CmsPath + "assets/admincontrols/adminpage.ascx");
                    FindAdminControls();

                    // set master selector
                    PopulateMasterPageList();

                    webpageAddButton.Click += new EventHandler(PurplePageAddButton_Click);

                    // fill in the details
                    webpageFilenamePrefix.Text = (!webpage.IsSiteRoot) ? webpage.Url + "/" : "";

                    // versions
                    webpageVersionsRepeater.DataSource = Webpages.GetWebpageRevision(webpage.WebpageID);
                    webpageVersionsRepeater.DataBind();

                    _form.Controls.Add(AdminControl);
                }

                // add common header to first control if needed
                string commonHeader = webpage.CommonAreaHeader;
                if (string.IsNullOrWhiteSpace(commonHeader) && !webpage.IgnoreParentHeader)
                {
                    // go back until the parent is null or we find a
                    Webpage parent = webpage.Parent;
                    do
                    {
                        if (!string.IsNullOrWhiteSpace(parent.CommonAreaHeader))
                        {
                            commonHeader = parent.CommonAreaHeader;
                            break;
                        }


                        parent = parent.Parent;
                    } while (parent != null && !parent.IsSiteRoot);
                }
                // add it if it exists
                if (!String.IsNullOrWhiteSpace(commonHeader))
                {
                    ContentPlaceHolders[0].Controls.Add(new LiteralControl(commonHeader));
                }


                // go through the webpage areas
                foreach (WebpageArea area in webpage.Areas)
                {
                    // get the right placeholder
                    ContentPlaceHolder placeholder = ContentPlaceHolders.Find(c => c.ID == area.ContentPlaceHolderID);

                    // use default
                    if (placeholder == null)
                    {
                        placeholder = ContentPlaceHolders[0];
                    }


                    // build control/HTML parts
                    string content = area.ContentHtml;

                    // fix extra paragraph tags for controls
                    content = _controlFixRegex.Replace(content, "[control:${1}]");

                    // override with single control
                    if (!String.IsNullOrWhiteSpace(area.ControlName))
                    {
                        content = "[control:" + area.ControlName + "]";
                    }


                    // search for controls, load them and create them
                    int             currentPosition = 0;
                    MatchCollection controlMatches  = _controlRegex.Matches(content);

                    if (controlMatches.Count == 0)
                    {
                        // Plain HTML
                        placeholder.Controls.Add(new LiteralControl(area.ContentHtml));
                    }
                    else
                    {
                        foreach (Match controlMatch in controlMatches)
                        {
                            // Add literal for content before custom tag should it exist.
                            if (controlMatch.Index > currentPosition)
                            {
                                placeholder.Controls.Add(new LiteralControl(content.Substring(currentPosition, controlMatch.Index - currentPosition)));
                            }

                            // Now lets add our user control.
                            try
                            {
                                string  all         = controlMatch.Groups[1].Value.Trim();
                                Control usercontrol = null;

                                if (!all.EndsWith(".ascx", StringComparison.OrdinalIgnoreCase))
                                {
                                    int index = all.IndexOf(".ascx", StringComparison.OrdinalIgnoreCase) + 5;
                                    usercontrol = LoadControl("~/cms/content/controls/" + all.Substring(0, index));

                                    string   parameters      = Server.HtmlDecode(all.Substring(index));
                                    Type     type            = usercontrol.GetType();
                                    string[] paramCollection = parameters.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);

                                    foreach (string param in paramCollection)
                                    {
                                        string name  = param.Split('=')[0].Trim();
                                        string value = param.Split('=')[1].Trim();
                                        System.Reflection.PropertyInfo property = type.GetProperty(name);
                                        property.SetValue(usercontrol, Convert.ChangeType(value, property.PropertyType, CultureInfo.InvariantCulture), null);
                                    }
                                }
                                else
                                {
                                    usercontrol = LoadControl("~/cms/content/controls/" + all);
                                }

                                placeholder.Controls.Add(usercontrol);

                                // Now we will update our position.
                                //currentPosition = controlMatch.Index + controlMatch.Groups[0].Length;
                            }
                            catch (Exception controlLoadException)
                            {
                                // Whoopss, can't load that control so lets output something that tells the developer that theres a problem.
                                placeholder.Controls.Add(new LiteralControl("ERROR - UNABLE TO LOAD CONTROL : " + "~/cms/content/controls/" + controlMatch.Groups[1].Value + "<br />" + controlLoadException.ToString()));
                            }

                            currentPosition = controlMatch.Index + controlMatch.Groups[0].Length;
                        }

                        // final text

                        // Add literal for content before custom tag should it exist.
                        if (content.Length > currentPosition)
                        {
                            placeholder.Controls.Add(new LiteralControl(content.Substring(currentPosition)));
                        }



                        // check for form needs
                        bool requiresForm = CheckRequiresForm(placeholder);;
                        if (requiresForm)
                        {
                            if (formMode == FormMode.Container)
                            {
                                // transfer controls to form
                                System.Web.UI.HtmlControls.HtmlForm form = new System.Web.UI.HtmlControls.HtmlForm();
                                while (placeholder.HasControls())
                                {
                                    form.Controls.Add(placeholder.Controls[0]);
                                }

                                // add form
                                placeholder.Controls.Add(form);
                            }
                            else if (formMode == FormMode.WholePage)
                            {
                                AddFormToBody();
                            }
                        }
                    }



                    #region old rendercode

                    /*
                     *                  if (!String.IsNullOrWhiteSpace(area.ControlName))
                     *                  {
                     *
                     *                          // find the ASCX file
                     *                          string controlVPath = PurpleSettings.CmsPath + "/content/controls/" + area.ControlName;
                     *                          string controlPath = Server.MapPath(controlVPath);
                     *
                     *                          if (File.Exists(controlPath))
                     *                          {
                     *                                  Control control = LoadControl(controlVPath);
                     *                                  bool requiresForm = CheckRequiresForm( control); ;
                     *                                  if (requiresForm)
                     *                                  {
                     *                                          if (formMode == FormMode.Container)
                     *                                          {
                     *                                                  System.Web.UI.HtmlControls.HtmlForm form = new System.Web.UI.HtmlControls.HtmlForm();
                     *                                                  placeholder.Controls.Add(form);
                     *                                                  form.Controls.Add(control);
                     *                                          }
                     *                                          else if (formMode == FormMode.WholePage)
                     *                                          {
                     *                                                  AddFormToBody();
                     *                                          }
                     *                                  }
                     *                                  else
                     *                                  {
                     *                                          placeholder.Controls.Add(control);
                     *                                  }
                     *                          }
                     *                          else
                     *                          {
                     *                                  placeholder.Controls.Add(new LiteralControl("<p>No control at :" + controlVPath + "</p>"));
                     *                          }
                     *
                     *                  }
                     *                  else
                     *                  {
                     *
                     *
                     *
                     *  // search for controls, load them and create them
                     *  string content = area.ContentHtml;
                     *  int currentPosition = 0;
                     *  MatchCollection controlMatches = _controlRegex.Matches(content);
                     *
                     *  if (controlMatches.Count == 0)
                     *  {
                     *      // old HTML only code
                     *      placeholder.Controls.Add(new LiteralControl(area.ContentHtml));
                     *  }
                     *  else
                     *  {
                     *
                     *      foreach (Match controlMatch in controlMatches)
                     *      {
                     *          // Add literal for content before custom tag should it exist.
                     *          if (controlMatch.Index > currentPosition)
                     *          {
                     *              placeholder.Controls.Add(new LiteralControl(content.Substring(currentPosition, controlMatch.Index - currentPosition)));
                     *          }
                     *
                     *          // Now lets add our user control.
                     *          try
                     *          {
                     *              string all = controlMatch.Groups[1].Value.Trim();
                     *              Control usercontrol = null;
                     *
                     *              if (!all.EndsWith(".ascx", StringComparison.OrdinalIgnoreCase))
                     *              {
                     *                  int index = all.IndexOf(".ascx", StringComparison.OrdinalIgnoreCase) + 5;
                     *                  usercontrol = LoadControl("~/cms/content/controls/" + all.Substring(0, index));
                     *
                     *                  string parameters = Server.HtmlDecode(all.Substring(index));
                     *                  Type type = usercontrol.GetType();
                     *                  string[] paramCollection = parameters.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                     *
                     *                  foreach (string param in paramCollection)
                     *                  {
                     *                      string name = param.Split('=')[0].Trim();
                     *                      string value = param.Split('=')[1].Trim();
                     *                      System.Reflection.PropertyInfo property = type.GetProperty(name);
                     *                      property.SetValue(usercontrol, Convert.ChangeType(value, property.PropertyType, CultureInfo.InvariantCulture), null);
                     *                  }
                     *              }
                     *              else
                     *              {
                     *                  usercontrol = LoadControl("~/cms/content/controls/" + all);
                     *              }
                     *
                     *              placeholder.Controls.Add(usercontrol);
                     *
                     *              // Now we will update our position.
                     *              //currentPosition = myMatch.Index + myMatch.Groups[0].Length;
                     *          }
                     *          catch (Exception controlLoadException)
                     *          {
                     *              // Whoopss, can't load that control so lets output something that tells the developer that theres a problem.
                     *              placeholder.Controls.Add(new LiteralControl("ERROR - UNABLE TO LOAD CONTROL : " + "~/cms/content/controls/" + controlMatch.Groups[1].Value + "<br />" + controlLoadException.ToString()));
                     *          }
                     *
                     *          currentPosition = controlMatch.Index + controlMatch.Groups[0].Length;
                     *      }
                     *
                     *
                     *      // check for form needs
                     *      bool requiresForm = CheckRequiresForm(placeholder); ;
                     *      if (requiresForm)
                     *      {
                     *          if (formMode == FormMode.Container)
                     *          {
                     *              // transfer controls to form
                     *              System.Web.UI.HtmlControls.HtmlForm form = new System.Web.UI.HtmlControls.HtmlForm();
                     *              while (placeholder.HasControls())
                     *              {
                     *                  form.Controls.Add(placeholder.Controls[0]);
                     *              }
                     *
                     *              // add form
                     *              placeholder.Controls.Add(form);
                     *
                     *          }
                     *          else if (formMode == FormMode.WholePage)
                     *          {
                     *              AddFormToBody();
                     *          }
                     *      }
                     *  }
                     *
                     * }
                     */
                    #endregion
                }
            }
            else if (pageMode == PageMode.Edit)
            {
                // just in case
                AddFormToBody();

                // main edit control
                AdminControl = LoadControl(PurpleSettings.CmsPath + "assets/admincontrols/editpage.ascx");
                _form.Controls.Add(AdminControl);

                // attach all the controls
                FindAdminControls();

                // special cases
                if (webpage.IsSiteRoot)
                {
                    webpageFilename.Enabled = false;
                    webpageUrl.Enabled      = false;
                }


                // main attributes
                webpageFilename.Text        = webpage.Filename;
                webpagePageTitle.Text       = webpage.Title;
                webpageMenuTitle.Text       = webpage.MenuTitle;
                webpageMetaDescription.Text = webpage.MetaDescription;
                webpageMetaKeywords.Text    = webpage.MetaKeywords;
                webpageFilenamePrefix.Text  = (!webpage.IsSiteRoot && !webpage.Parent.IsSiteRoot) ? webpage.Parent.Url + "/" : "";
                webpageUrl.Text             = webpage.Url;
                webpageForceSsl.Checked     = webpage.ForceSsl;
                webpageShowInMenu.Checked   = webpage.ShowInMenu;
                webpageSortOrder.Text       = webpage.SortOrder.ToString();

                webpageCommonAreaHeader.Text      = webpage.CommonAreaHeader;
                webpageContentExpirationDate.Text = webpage.ContentExpirationDate.ToString();
                webpageIgnoreParentHeader.Checked = webpage.IgnoreParentHeader;

                // menu type enum



                // master pages
                PopulateMasterPageList();

                // permissions
                string[] allEditors = System.Web.Security.Roles.GetUsersInRole(PurpleSettings.RoleEditor);
                webpageEditors.DataSource = allEditors;
                webpageEditors.DataBind();

                List <string> pageEditors = webpage.Editors.Split(new char[] { ',' }).ToList <String>();
                foreach (ListItem li in webpageEditors.Items)
                {
                    if (pageEditors.Contains(li.Value))
                    {
                        li.Selected = true;
                    }
                }


                // attach save event
                webpageSaveButton.Click += new EventHandler(PurplePageSaveButton_Click);


                // WEBPAGE AREAS


                // list of control folders
                string        controlBase    = Server.MapPath(PurpleSettings.CmsPath + "content/controls/");
                List <string> controlFolders = new List <string>();
                UtilityMethods.FindFoldersRecursive(controlFolders, controlBase);

                // list of controls
                List <string> availableControls = new List <string>();
                UtilityMethods.FindFilesRecursive(availableControls, "*.ascx", controlBase, true);


                // go through the webpage areas
                foreach (WebpageArea area in webpage.Areas)
                {
                    // get the right placeholder
                    ContentPlaceHolder placeholder = ContentPlaceHolders.Find(c => c.ID == area.ContentPlaceHolderID);

                    // use default
                    if (placeholder == null)
                    {
                        placeholder = ContentPlaceHolders[0];
                    }


                    Control areaControl = LoadControl(PurpleSettings.CmsPath + "assets/admincontrols/editarea.ascx");

                    // grab the html area
                    TextBox htmlContent = areaControl.FindControl("HtmlContent") as TextBox;
                    htmlContent.Text = area.ContentHtml;


                    // fill in the *.ascx controls
                    DropDownList controlName = areaControl.FindControl("ControlName") as DropDownList;
                    controlName.DataSource = availableControls;
                    controlName.DataBind();
                    controlName.Items.Insert(0, new ListItem("-- No Control (use HTML) --", ""));

                    if (!String.IsNullOrWhiteSpace(area.ControlName) && controlName.Items.FindByValue(area.ControlName.Replace(".ascx", "")) != null)
                    {
                        controlName.Items.FindByValue(area.ControlName.Replace(".ascx", "")).Selected = true;
                    }

                    // fill in the upload folders
                    DropDownList controlUploadFolder = areaControl.FindControl("ControlUploadFolder") as DropDownList;
                    controlUploadFolder.DataSource = controlFolders;
                    controlUploadFolder.DataBind();
                    controlUploadFolder.Items.Insert(0, new ListItem("-- Root Folder --", ""));

                    // attach event to the upload button
                    (areaControl.FindControl("ControlUploadButton") as Button).Click += new EventHandler(ControlUploadButton_Click);


                    // add this control
                    placeholder.Controls.Add(areaControl);
                }
            }

            base.OnInit(e);
        }