public void InstallContent(Module module, string configInfo)
        {
            HtmlContent htmlContent = new HtmlContent();

            htmlContent.ModuleId = module.ModuleId;
            if (configInfo.StartsWith("~/"))
            {
                if (File.Exists(HostingEnvironment.MapPath(configInfo)))
                {
                    htmlContent.Body = File.ReadAllText(HostingEnvironment.MapPath(configInfo), Encoding.UTF8);
                }
            }
            else
            {
                htmlContent.Body = ResourceHelper.GetMessageTemplate(CultureInfo.CurrentUICulture, configInfo);
            }

            htmlContent.ModuleGuid = module.ModuleGuid;

            SiteSettings siteSettings = new SiteSettings(module.SiteId);
            SiteUser     adminUser    = null;

            if (siteSettings.UseEmailForLogin)
            {
                adminUser = new SiteUser(siteSettings, "*****@*****.**");
                if (adminUser.UserId == -1)
                {
                    adminUser = null;
                }
            }
            else
            {
                adminUser = new SiteUser(siteSettings, "admin");
                if (adminUser.UserId == -1)
                {
                    adminUser = null;
                }
            }

            if (adminUser != null)
            {
                htmlContent.UserGuid        = adminUser.UserGuid;
                htmlContent.LastModUserGuid = adminUser.UserGuid;
            }

            HtmlRepository repository = new HtmlRepository();

            repository.Save(htmlContent);
        }
        private void UpdateContent()
        {
            if (string.IsNullOrEmpty(submittedContent))
            {
                return;
            }

            if (!EditIsAllowed())
            {
                return;
            }

            if ((ViewMode == PageViewMode.WorkInProgress) && (WebConfigSettings.EnableContentWorkflow) && (CurrentSite.EnableContentWorkflow))
            {
                if (workInProgress != null)
                {
                    if (!editDraft)
                    {
                        return;
                    }

                    workInProgress.ContentText     = submittedContent;
                    workInProgress.LastModUserGuid = currentUser.UserGuid;
                    workInProgress.Save();
                }
                else
                {
                    //draft version doesn't exist - create it:
                    ContentWorkflow.CreateDraftVersion(
                        CurrentSite.SiteGuid,
                        submittedContent,
                        string.Empty,
                        -1,
                        Guid.Empty,
                        this.module.ModuleGuid,
                        currentUser.UserGuid);
                }
            }
            else
            {
                // edit live content
                if (userCanOnlyEditAsDraft)
                {
                    return;
                }

                html = repository.Fetch(module.ModuleId);
                if (html == null)
                {
                    html            = new HtmlContent();
                    html.ModuleId   = module.ModuleId;
                    html.ModuleGuid = module.ModuleGuid;
                }

                html.Body = submittedContent;
                //these will really only be saved if it is a new html instance
                html.CreatedDate     = DateTime.UtcNow;
                html.UserGuid        = currentUser.UserGuid;
                html.LastModUserGuid = currentUser.UserGuid;

                if (module != null)
                {
                    html.ModuleGuid = module.ModuleGuid;
                }
                html.LastModUtc = DateTime.UtcNow;


                if ((enableContentVersioning) && (html.ItemId > -1))
                {
                    html.CreateHistory(CurrentSite.SiteGuid);
                }

                html.ContentChanged += new ContentChangedEventHandler(html_ContentChanged);

                repository.Save(html);

                CurrentPage.UpdateLastModifiedTime();
                CacheHelper.ClearModuleCache(module.ModuleId);

                SiteUtils.QueueIndexing();
            }
        }
Esempio n. 3
0
        private void SaveHtml(bool draft)
        {
            if (html == null)
            {
                return;
            }

            this.itemId = html.ItemId;

            html.ContentChanged += new ContentChangedEventHandler(html_ContentChanged);

            bool   saveHtml = true;
            string htmlBody = edContent.Text;

            if (draft)
            {
                //ContentWorkflow wip = ContentWorkflow.GetWorkInProgress(this.module.ModuleGuid);
                //dont update the actual data, but edit/create the draft version:
                if (workInProgress != null)
                {
                    if (workInProgress.Status != ContentWorkflowStatus.Draft)
                    {
                        if ((workInProgress.Status == ContentWorkflowStatus.AwaitingApproval) && (userCanEdit))
                        {
                            // do nothing, let the editor update the draft without changing the status
                        }
                        else
                        {
                            //otherwise set the status back to draft
                            workInProgress.Status = ContentWorkflowStatus.Draft;
                        }
                    }

                    workInProgress.ContentText = edContent.Text;
                    workInProgress.Save();
                }
                else
                {
                    //draft version doesn't exist - create it:
                    ContentWorkflow.CreateDraftVersion(
                        siteSettings.SiteGuid,
                        edContent.Text,
                        string.Empty,
                        -1,
                        Guid.Empty,
                        this.module.ModuleGuid,
                        currentUser.UserGuid);
                }

                //if this is a new item, then we want to save it even though we will be saving it with no html,
                //this ensures that there is a record there from the start:
                if (html.ItemId < 1)
                {
                    saveHtml = true;
                    //save with no content as there will be no live content
                    htmlBody = String.Empty;
                }
                else
                {
                    saveHtml = false;
                }
            }

            if (saveHtml)
            {
                //update existing HTML content:

                html.Body            = htmlBody;
                html.LastModUserGuid = currentUser.UserGuid;
                if (module != null)
                {
                    html.ModuleGuid = module.ModuleGuid;
                }
                html.LastModUtc = DateTime.UtcNow;


                if (enableContentVersioning && !draft)
                {
                    html.CreateHistory(siteSettings.SiteGuid);
                }

                repository.Save(html);
            }
            CurrentPage.UpdateLastModifiedTime();
            CacheHelper.TouchCacheDependencyFile(cacheDependencyKey);

            SiteUtils.QueueIndexing();


            if (hdnReturnUrl.Value.Length > 0)
            {
                WebUtils.SetupRedirect(this, hdnReturnUrl.Value);
                return;
            }

            WebUtils.SetupRedirect(this, SiteUtils.GetCurrentPageUrl());
        }
Esempio n. 4
0
        private void SaveHtml(bool draft)
        {
            if (html == null)
            {
                return;
            }

            this.itemId = html.ItemId;

            html.ContentChanged += new ContentChangedEventHandler(html_ContentChanged);

            bool   saveHtml = true;
            string htmlBody = edContent.Text;

            if (draft)
            {
                //ContentWorkflow wip = ContentWorkflow.GetWorkInProgress(this.module.ModuleGuid);
                //dont update the actual data, but edit/create the draft version:
                if (workInProgress != null)
                {
                    if (workInProgress.Status != ContentWorkflowStatus.Draft)
                    {
                        //JOE DAVIS
                        if ((workInProgress.Status == ContentWorkflowStatus.AwaitingApproval || workInProgress.Status == ContentWorkflowStatus.AwaitingPublishing) &&
                            ((userCanEdit) || UserCanApproveDraftModule(module.ModuleId, HtmlContent.FeatureGuid)))
                        {
                            // do nothing, let the editor update the draft without changing the status
                        }
                        else
                        {
                            //otherwise set the status back to draft
                            workInProgress.Status = ContentWorkflowStatus.Draft;
                        }
                    }

                    workInProgress.ContentText     = edContent.Text;
                    workInProgress.LastModUserGuid = currentUser.UserGuid;
                    workInProgress.Save();
                }
                else
                {
                    //draft version doesn't exist - create it:
                    ContentWorkflow.CreateDraftVersion(
                        siteSettings.SiteGuid,
                        edContent.Text,
                        string.Empty,
                        -1,
                        Guid.Empty,
                        this.module.ModuleGuid,
                        currentUser.UserGuid);
                }

                //if this is a new item, then we want to save it even though we will be saving it with no html,
                //this ensures that there is a record there from the start:
                if (html.ItemId < 1)
                {
                    saveHtml = true;
                    //save with no content as there will be no live content
                    htmlBody = String.Empty;
                }
                else
                {
                    saveHtml = false;
                }
            }

            if (saveHtml)
            {
                html.Body = htmlBody;
                //these will really only be saved if it is a new html instance
                html.CreatedDate = DateTime.UtcNow;
                html.UserGuid    = currentUser.UserGuid;

                html.LastModUserGuid = currentUser.UserGuid; //this is only used for update

                if (divExcludeFromRecentContent.Visible)
                {
                    html.ExcludeFromRecentContent = chkExcludeFromRecentContent.Checked;
                }

                if (module != null)
                {
                    html.ModuleGuid = module.ModuleGuid;
                }
                html.LastModUtc = DateTime.UtcNow;


                if (enableContentVersioning && !draft)
                {
                    html.CreateHistory(siteSettings.SiteGuid);
                }

                repository.Save(html);
            }
            else
            {
                if ((divExcludeFromRecentContent.Visible) && (chkExcludeFromRecentContent.Checked != html.ExcludeFromRecentContent))
                {
                    html.ExcludeFromRecentContent = chkExcludeFromRecentContent.Checked;
                    repository.Save(html);
                }
            }

            if (!draft)
            {
                CurrentPage.UpdateLastModifiedTime();
                CacheHelper.ClearModuleCache(moduleId);

                SiteUtils.QueueIndexing();
            }


            //if (hdnReturnUrl.Value.Length > 0)
            //{

            //    WebUtils.SetupRedirect(this, hdnReturnUrl.Value);
            //    return;
            //}

            //WebUtils.SetupRedirect(this, SiteUtils.GetCurrentPageUrl());
        }