コード例 #1
0
        public ActionResult Page(string id)
        {
#if PUB
            var page = new PageModelBuilder <PubPage>(_db).GetPage(id);
#elif CMS
            var page = new PageModelBuilder <CmsPage>(_db).GetPage(id);
#endif
            if (page == null)
            {
                throw new HttpException(404, "Page not found");
            }

            var webpartHeaders = new StringBuilder();
            var havingWebPart  = false;

            page.ContentHtml.Content = _pageEngine.ReplaceTokens(
                page: page,
                webpartHeaders: webpartHeaders,
                havingWebPart: out havingWebPart,
                controllerContext: ControllerContext);

            ViewBag.HavingWebPart  = havingWebPart;
            ViewBag.WebpartHeaders = webpartHeaders.ToString();

#if CMS
            ViewBag.AccessMode = SecurityHelper.PageAccessMode(_db, page);
#endif

            ViewBag.NaviNode = page.NaviNode;
            ViewBag.BaseNode = CmsPageBase.FindBaseNode(page);

            var viewHtml = ViewRenderer.RenderViewToString(ControllerContext, "~/Core/Containers/Views/Cms/Page.cshtml", page);
            return(Content(viewHtml, "text/html"));
        }
コード例 #2
0
ファイル: PageCmsController.cs プロジェクト: pir8aye/FRA-CMS
        public ActionResult Version(int id)
        {
            VerPage vPage = _db.Set <VerPage>().SingleOrDefault(e => e.VerId == id);

            if (vPage == null)
            {
                return(new HttpNotFoundResult("Page version not found"));
            }

            CmsPage page = new CmsPage();

            CopyProperties(vPage, page);

            page.Id       = vPage.Id;
            page.NaviNode = _db.Set <NaviNode>().SingleOrDefault(
                e => e.Id == vPage.NaviNodeId);

            StringBuilder webpartHeaders = new StringBuilder();

            bool havingWebPart = false;

            page.ContentHtml.Content = _pageEngine.ReplaceTokens(
                page: page,
                webpartHeaders: webpartHeaders,
                havingWebPart: out havingWebPart,
                controllerContext: this.ControllerContext);

            PermissionType accessMode = SecurityHelper.PageAccessMode(_db, page);

            ViewBag.AccessMode = accessMode;
            ViewBag.VerId      = vPage.VerId;
            ViewBag.BaseNode   = CmsPageBase.FindBaseNode(page);

            return(View(page));
        }
コード例 #3
0
ファイル: PageCmsController.cs プロジェクト: pir8aye/FRA-CMS
        public ActionResult Edit(EditPageModel editPage)
        {
            CmsPage        page       = _db.Set <CmsPage>().Single(e => e.Id == editPage.Id);
            PermissionType accessMode = SecurityHelper.PageAccessMode(_db, page);

            if (accessMode < PermissionType.Edit)
            {
                throw new Exception("Access Denided.");
            }

            // TODO Check config to see what the page content format is
            if (!editPage.Content.StartsWith("{"))
            {
                ModelState.AddModelError("Error", "Content format does not match. Please refresh your page.");
            }

            if (ModelState.IsValid)
            {
                CopyProperties(editPage, page);
                page.Status = CmsPage.STATUS_CHANGE_SAVED;

                if (editPage.Layout == 8)
                {
                    //TODO HARD CODED
                    page.Title = "Summary";
                }

                // Only save the page when it has a unique URL.
                CmsPage pageWithDuplicateUrl = _db.Set <CmsPage>().SingleOrDefault(e => e.Url.Equals(page.Url, StringComparison.InvariantCultureIgnoreCase));
                if (pageWithDuplicateUrl == null || pageWithDuplicateUrl.Id == editPage.Id)
                {
                    _db.SaveChanges();
                    return(Redirect("/" + page.Url));
                }
                else
                {
                    ModelState.AddModelError("NaviTitle", "Cannot have same page URL in the same navigation section.");
                }
                //return RedirectToAction("Page", "Cms", new { id = page.FriendlyId });
            }

            var naviNode = page.NaviNode;

            ViewBag.NaviNode   = naviNode;
            ViewBag.BaseNode   = CmsPageBase.FindBaseNode(naviNode);
            ViewBag.AccessMode = accessMode;
            ViewBag.Status     = CmsPage.STATUS_EDITING_START;
            ViewBag.Modified   = DateTime.Now;

            bool havingWebPart = false;

            editPage.Content = _pageEngine.ReplaceTokens(
                page: page,
                webpartHeaders: new StringBuilder(),
                havingWebPart: out havingWebPart,
                controllerContext: this.ControllerContext,
                isEditState: true);

            return(View(editPage));
        }
コード例 #4
0
ファイル: PageCmsController.cs プロジェクト: pir8aye/FRA-CMS
        public ActionResult Edit(string id)
        {
            int     internalId = CmsPage.FromFriendlyId(id);
            CmsPage page       = _db.Set <CmsPage>().Single(e => e.Id == internalId);

            PermissionType accessMode = SecurityHelper.PageAccessMode(_db, page);

            if (accessMode < PermissionType.Edit)
            {
                //return RedirectToAction("Page", "Cms", new { id = id });
                return(Redirect("/" + page.Url));
            }

            if ((page.Status == CmsPage.STATUS_EDITING_START ||
                 page.Status == CmsPage.STATUS_EDITING_AGAIN) &&
                page.ModifiedBy != User.Identity.Name.ToUpper())
            {
                //return RedirectToAction("Page", "Cms", new { id = page.FriendlyId });
                return(Redirect("/" + page.Url));
            }

            EditPageModel editPage = new EditPageModel();

            CopyProperties(page, editPage);

            bool havingWebPart = false;

            StringBuilder webpartHeaders = new StringBuilder();

            editPage.Content = _pageEngine.ReplaceTokens(
                page: page,
                webpartHeaders: webpartHeaders,
                havingWebPart: out havingWebPart,
                controllerContext: this.ControllerContext,
                isEditState: true);

            ViewBag.HavingWebPart  = havingWebPart;
            ViewBag.WebpartHeaders = webpartHeaders.ToString();

            ViewBag.NaviNode   = page.NaviNode;
            ViewBag.BaseNode   = CmsPageBase.FindBaseNode(page);
            ViewBag.ModifiedBy = HttpContext.User.Identity.Name;
            ViewBag.AccessMode = accessMode;
            ViewBag.Modified   = DateTime.Now;
            ViewBag.Status     = CmsPage.STATUS_EDITING_START;
            editPage.Status    = CmsPage.STATUS_EDITING_START;
            return(View(editPage));
        }
コード例 #5
0
ファイル: PageCmsController.cs プロジェクト: pir8aye/FRA-CMS
        public ActionResult Create(EditPageModel editPage, string isCreateNewSection, string newSectionName)
        {
            NaviNode currentNode = _db.Set <NaviNode>().Single(e => e.Id == editPage.NaviNodeId);

            PermissionType accessMode = SecurityHelper.NaviAccessMode(_db, currentNode);

            if (accessMode < PermissionType.Create)
            {
                throw new Exception("Access Denided.");
            }

            // TODO: add site specical chc
            if (CmsHelper.Site == "fratalk")
            {
                if (string.IsNullOrEmpty(editPage.Keywords))
                {
                    ModelState.AddModelError("keywords", "The topics field is required.");
                }
            }


            if (ModelState.IsValid)
            {
                CmsPage page = new CmsPage();
                CopyProperties(editPage, page);

                page.Status = CmsPage.STATUS_CHANGE_SAVED;

                if (editPage.Layout == 8)
                {
                    //TODO HARD CODED
                    isCreateNewSection = "1";
                    newSectionName     = editPage.Title;
                    page.Title         = "Summary";
                    page.NaviTitle     = "Summary";
                }

                if (isCreateNewSection == "1" && newSectionName != null && newSectionName.Length > 0)
                {
                    NaviNode naviNode = new NaviNode();
                    naviNode.NodeName  = newSectionName;
                    naviNode.Parent    = page.NaviNode;
                    naviNode.MenuOrder = CountChildren(page.NaviNode.Id);
                    naviNode.Type      = page.NaviNode.Type;

                    naviNode.Modified   = DateTime.Now;
                    naviNode.ModifiedBy = User.Identity.Name.ToUpper();
                    naviNode.Created    = DateTime.Now;
                    naviNode.CreatedBy  = User.Identity.Name.ToUpper();

                    page.NaviNode  = naviNode;
                    page.MenuOrder = 0;
                    page.Type      = _db.Set <ContentType>().SingleOrDefault(e => e.Title == "BLOG HOME") ?? naviNode.Type;
                }
                else
                {
                    page.MenuOrder = CountChildren(page.NaviNode.Id);
                    page.Type      = page.NaviNode.Type;
                }
                _urlHelper.UpdatePageUrl(page);

                // Only save the page when it has a unique URL.
                CmsPage pageWithDuplicateUrl = _db.Set <CmsPage>().SingleOrDefault(e => e.Url.Equals(page.Url, StringComparison.InvariantCultureIgnoreCase));
                if (pageWithDuplicateUrl == null)
                {
                    _db.Set <CmsPage>().Add(page);
                    _db.SaveChanges();
                    return(Redirect("/" + page.Url));
                }
                else
                {
                    ModelState.AddModelError("NaviTitle", "Cannot have same page URL in the same navigation section.");
                }
            }
            // The first page in the menu is the return page
            // if create page action is canceled.
            CmsPage returnPage = currentNode.Pages.OrderBy(e => e.MenuOrder).FirstOrDefault();

            ViewBag.ReturnUrl = "/" + (returnPage == null ? "" : returnPage.Url);

            ViewBag.NaviNode   = currentNode;
            ViewBag.BaseNode   = CmsPageBase.FindBaseNode(currentNode);
            ViewBag.AccessMode = accessMode;

            bool havingWebPart = false;

            editPage.Content = _pageEngine.ReplaceTokens(
                page: new CmsPage
            {
                Id   = editPage.Id,
                Html = new CmsPageHtml
                {
                    Content = editPage.Content
                },
                NaviNode = currentNode,
                Layout   = editPage.Layout
            },
                webpartHeaders: new StringBuilder(),
                havingWebPart: out havingWebPart,
                controllerContext: this.ControllerContext,
                isEditState: true);

            return(View(editPage));
        }
コード例 #6
0
ファイル: PageCmsController.cs プロジェクト: pir8aye/FRA-CMS
        //
        // GET: /Page/Create
        //id is the navigation id
        public ActionResult Create(int id, int layoutId = 1)
        {
            NaviNode naviNode = _db.Set <NaviNode>().Single(e => e.Id == id);

            PermissionType accessMode = SecurityHelper.NaviAccessMode(_db, naviNode);

            if (accessMode < PermissionType.Create)
            {
                throw new Exception("Access Denided.");
            }

            ViewBag.NaviNode   = naviNode;
            ViewBag.AccessMode = accessMode;
            ViewBag.BaseNode   = CmsPageBase.FindBaseNode(naviNode);

            EditPageModel editPageModel = new EditPageModel();

            editPageModel.NaviNodeId = naviNode.Id;

            var layout = _db.Set <PageLayout>().SingleOrDefault(e => e.Id == layoutId);

            if (layout == null)
            {
                layout = _db.Set <PageLayout>().First();
            }

            bool havingWebPart = false;

            StringBuilder webpartHeaders = new StringBuilder();
            string        template       = layout.Template;
            var           tempPage       = new CmsPage
            {
                Id   = id,
                Html = new CmsPageHtml
                {
                    Content = layout.Template
                },
                Layout   = layout.Id,
                NaviNode = naviNode
            };

            // hack
            if (tempPage.Layout == 10)
            {
                tempPage.Html.Content = new JavaScriptSerializer().Serialize(new
                {
                    Summaryregion = "Post Summary",
                    region1       = "Post Content"
                });
            }
            editPageModel.Content = _pageEngine.ReplaceTokens(
                page: tempPage,
                webpartHeaders: webpartHeaders,
                havingWebPart: out havingWebPart,
                controllerContext: ControllerContext,
                isEditState: true);
            editPageModel.Layout   = layout.Id;
            editPageModel.Type     = layout.Type.Title;
            ViewBag.HavingWebPart  = havingWebPart;
            ViewBag.WebpartHeaders = webpartHeaders.ToString();

            // The first page in the menu is the return page
            // if create page action is canceled.
            CmsPage returnPage = naviNode.Pages.OrderBy(e => e.MenuOrder).FirstOrDefault();

            ViewBag.ReturnUrl = "/" + (returnPage == null ? "" : returnPage.Url);

            editPageModel.Status        = CmsPage.STATUS_EDITING_START;
            editPageModel.IsCommentable = true;
            return(View(editPageModel));
        }