public override void DeleteContent(int moduleId, Guid moduleGuid)
 {
     ContentHistory.DeleteByContent(moduleGuid);
     ContentWorkflow.DeleteByModule(moduleGuid);
     HtmlRepository repository = new HtmlRepository();
     repository.DeleteByModule(moduleId);
 }
예제 #2
0
        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);
        }
예제 #3
0
        public static void CreatePage(SiteSettings siteSettings, ContentPage contentPage, PageSettings parentPage)
        {
            PageSettings pageSettings = new PageSettings();
            pageSettings.PageGuid = Guid.NewGuid();

            if (parentPage != null)
            {
                pageSettings.ParentGuid = parentPage.PageGuid;
                pageSettings.ParentId = parentPage.PageId;
            }

            pageSettings.SiteId = siteSettings.SiteId;
            pageSettings.SiteGuid = siteSettings.SiteGuid;
            pageSettings.AuthorizedRoles = contentPage.VisibleToRoles;
            pageSettings.EditRoles = contentPage.EditRoles;
            pageSettings.DraftEditOnlyRoles = contentPage.DraftEditRoles;
            pageSettings.CreateChildPageRoles = contentPage.CreateChildPageRoles;
            pageSettings.MenuImage = contentPage.MenuImage;
            pageSettings.PageMetaKeyWords = contentPage.PageMetaKeyWords;
            pageSettings.PageMetaDescription = contentPage.PageMetaDescription;

            CultureInfo uiCulture = Thread.CurrentThread.CurrentUICulture;
            if (WebConfigSettings.UseCultureOverride)
            {
                uiCulture = SiteUtils.GetDefaultUICulture(siteSettings.SiteId);
            }

            if (contentPage.ResourceFile.Length > 0)
            {
                pageSettings.PageName = ResourceHelper.GetResourceString(contentPage.ResourceFile, contentPage.Name, uiCulture, false);
                if (contentPage.Title.Length > 0)
                {
                    pageSettings.PageTitle = ResourceHelper.GetResourceString(contentPage.ResourceFile, contentPage.Title, uiCulture, false);
                }
            }
            else
            {
                pageSettings.PageName = contentPage.Name;
                pageSettings.PageTitle = contentPage.Title;
            }

            pageSettings.PageOrder = contentPage.PageOrder;
            pageSettings.Url = contentPage.Url;
            pageSettings.RequireSsl = contentPage.RequireSsl;
            pageSettings.ShowBreadcrumbs = contentPage.ShowBreadcrumbs;

            pageSettings.BodyCssClass = contentPage.BodyCssClass;
            pageSettings.MenuCssClass = contentPage.MenuCssClass;
            pageSettings.IncludeInMenu = contentPage.IncludeInMenu;
            pageSettings.IsClickable = contentPage.IsClickable;
            pageSettings.IncludeInSiteMap = contentPage.IncludeInSiteMap;
            pageSettings.IncludeInChildSiteMap = contentPage.IncludeInChildPagesSiteMap;
            pageSettings.AllowBrowserCache = contentPage.AllowBrowserCaching;
            pageSettings.ShowChildPageBreadcrumbs = contentPage.ShowChildPageBreadcrumbs;
            pageSettings.ShowHomeCrumb = contentPage.ShowHomeCrumb;
            pageSettings.ShowChildPageMenu = contentPage.ShowChildPagesSiteMap;
            pageSettings.HideAfterLogin = contentPage.HideFromAuthenticated;
            pageSettings.EnableComments = contentPage.EnableComments;

            pageSettings.Save();

            if (!FriendlyUrl.Exists(siteSettings.SiteId, pageSettings.Url))
            {
                if (!WebPageInfo.IsPhysicalWebPage(pageSettings.Url))
                {
                    FriendlyUrl friendlyUrl = new FriendlyUrl();
                    friendlyUrl.SiteId = siteSettings.SiteId;
                    friendlyUrl.SiteGuid = siteSettings.SiteGuid;
                    friendlyUrl.PageGuid = pageSettings.PageGuid;
                    friendlyUrl.Url = pageSettings.Url.Replace("~/", string.Empty);
                    friendlyUrl.RealUrl = "~/Default.aspx?pageid=" + pageSettings.PageId.ToInvariantString();
                    friendlyUrl.Save();
                }
            }

            foreach (ContentPageItem pageItem in contentPage.PageItems)
            {

                // tni-20130624: moduleGuidxxxx handling
                Guid moduleGuid2Use = Guid.Empty;
                bool updateModule = false;

                Module findModule = null;

                if (pageItem.ModuleGuidToPublish != Guid.Empty)
                {
                    Module existingModule = new Module(pageItem.ModuleGuidToPublish);
                    if (existingModule.ModuleGuid == pageItem.ModuleGuidToPublish && existingModule.SiteId == siteSettings.SiteId)
                    {
                        Module.Publish(pageSettings.PageGuid, existingModule.ModuleGuid, existingModule.ModuleId, pageSettings.PageId,
                            pageItem.Location, pageItem.SortOrder, DateTime.UtcNow, DateTime.MinValue);

                        // tni: I assume there's nothing else to do now so let's go to the next content...
                        continue;
                    }
                }
                else if (pageItem.ModuleGuid != Guid.Empty)
                {
                    findModule = new Module(pageItem.ModuleGuid);
                    if (findModule.ModuleGuid == Guid.Empty)
                    {
                        // Module does not exist, we can create new one with the specified Guid
                        moduleGuid2Use = pageItem.ModuleGuid;
                    }

                    if (findModule.ModuleGuid == pageItem.ModuleGuid && findModule.SiteId == siteSettings.SiteId)
                    {
                        // The module already exist, we'll update existing one
                        updateModule = true;
                        moduleGuid2Use = findModule.ModuleGuid;
                    }
                }
                //

                ModuleDefinition moduleDef = new ModuleDefinition(pageItem.FeatureGuid);

                // this only adds if its not already there
                try
                {
                    SiteSettings.AddFeature(siteSettings.SiteGuid, pageItem.FeatureGuid);
                }
                catch (Exception ex)
                {
                    log.Error(ex);
                }

                if (moduleDef.ModuleDefId > -1)
                {

                    Module module = null;
                    if (updateModule && (findModule != null))
                    {
                        module = findModule;
                    }
                    else
                    {
                        module = new Module();
                        module.ModuleGuid = moduleGuid2Use;
                    }

                    module.SiteId = siteSettings.SiteId;
                    module.SiteGuid = siteSettings.SiteGuid;
                    module.PageId = pageSettings.PageId;
                    module.ModuleDefId = moduleDef.ModuleDefId;
                    module.FeatureGuid = moduleDef.FeatureGuid;
                    module.PaneName = pageItem.Location;
                    if (contentPage.ResourceFile.Length > 0)
                    {
                        module.ModuleTitle
                            = ResourceHelper.GetResourceString(contentPage.ResourceFile, pageItem.ContentTitle, uiCulture, false);
                    }
                    else
                    {
                        module.ModuleTitle = pageItem.ContentTitle;
                    }
                    module.ModuleOrder = pageItem.SortOrder;
                    module.CacheTime = pageItem.CacheTimeInSeconds;
                    module.Icon = moduleDef.Icon;
                    module.ShowTitle = pageItem.ShowTitle;
                    module.AuthorizedEditRoles = pageItem.EditRoles;
                    module.DraftEditRoles = pageItem.DraftEditRoles;
                    module.ViewRoles = pageItem.ViewRoles;
                    module.IsGlobal = pageItem.IsGlobal;
                    module.HeadElement = pageItem.HeadElement;
                    module.HideFromAuthenticated = pageItem.HideFromAuthenticated;
                    module.HideFromUnauthenticated = pageItem.HideFromAnonymous;

                    module.Save();

                    if ((pageItem.Installer != null) && (pageItem.ConfigInfo.Length > 0))
                    {
                        //this is the newer implementation for populating feature content
                        pageItem.Installer.InstallContent(module, pageItem.ConfigInfo);
                    }
                    else
                    {
                        // legacy implementation for backward compatibility
                        if (
                            (pageItem.FeatureGuid == HtmlContent.FeatureGuid)
                            && (pageItem.ContentTemplate.EndsWith(".config"))
                            )
                        {
                            HtmlContent htmlContent = new HtmlContent();
                            htmlContent.ModuleId = module.ModuleId;
                            htmlContent.Body = ResourceHelper.GetMessageTemplate(uiCulture, pageItem.ContentTemplate);
                            htmlContent.ModuleGuid = module.ModuleGuid;
                            HtmlRepository repository = new HtmlRepository();
                            repository.Save(htmlContent);

                        }
                    }

                    // tni-20130624: handling module settings
                    foreach (KeyValuePair<string, string> item in pageItem.ModuleSettings)
                    {
                        ModuleSettings.UpdateModuleSetting(module.ModuleGuid, module.ModuleId, item.Key, item.Value);
                    }

                }
            }

            foreach (ContentPage childPage in contentPage.ChildPages)
            {
                CreatePage(siteSettings, childPage, pageSettings);
            }
        }
 public override void DeleteSiteContent(int siteId)
 {
     HtmlRepository repository = new HtmlRepository();
     repository.DeleteBySite(siteId);
 }
        public override void RebuildIndex(
            PageSettings pageSettings,
            string indexPath)
        {
            bool disableSearchIndex = ConfigHelper.GetBoolProperty("DisableSearchIndex", false);
            if (disableSearchIndex) { return; }

            if (pageSettings == null)
            {
                log.Error("pageSettings passed in to HtmlContentIndexBuilderProvider.RebuildIndex was null");
                return;
            }

            //don't index pending/unpublished pages
            if (pageSettings.IsPending) { return; }

            log.Info("HtmlContentIndexBuilderProvider indexing page - "
                + pageSettings.PageName);

            try
            {
                Guid htmlFeatureGuid
                    = new Guid("881e4e00-93e4-444c-b7b0-6672fb55de10");
                ModuleDefinition htmlFeature
                    = new ModuleDefinition(htmlFeatureGuid);

                List<PageModule> pageModules
                        = PageModule.GetPageModulesByPage(pageSettings.PageId);

                HtmlRepository repository = new HtmlRepository();

                DataTable dataTable = repository.GetHtmlContentByPage(
                    pageSettings.SiteId,
                    pageSettings.PageId);

                foreach (DataRow row in dataTable.Rows)
                {
                    bool includeInSearch = Convert.ToBoolean(row["IncludeInSearch"]);
                    bool excludeFromRecentContent = Convert.ToBoolean(row["ExcludeFromRecentContent"]);

                    IndexItem indexItem = new IndexItem();
                    indexItem.ExcludeFromRecentContent = excludeFromRecentContent;
                    indexItem.SiteId = pageSettings.SiteId;
                    indexItem.PageId = pageSettings.PageId;
                    indexItem.PageName = pageSettings.PageName;

                    string authorName = row["CreatedByName"].ToString();
                    string authorFirstName = row["CreatedByFirstName"].ToString();
                    string authorLastName = row["CreatedByLastName"].ToString();

                    if ((authorFirstName.Length > 0) && (authorLastName.Length > 0))
                    {
                        indexItem.Author = string.Format(CultureInfo.InvariantCulture,
                            Resource.FirstNameLastNameFormat, authorFirstName, authorLastName);
                    }
                    else
                    {
                        indexItem.Author = authorName;
                    }

                    if (!includeInSearch) { indexItem.RemoveOnly = true; }

                    // generally we should not include the page meta because it can result in duplicate results
                    // one for each instance of html content on the page because they all use the smae page meta.
                    // since page meta should reflect the content of the page it is sufficient to just index the content
                    if (WebConfigSettings.IndexPageKeywordsWithHtmlArticleContent)
                    {
                        indexItem.PageMetaDescription = pageSettings.PageMetaDescription;
                        indexItem.PageMetaKeywords = pageSettings.PageMetaKeyWords;
                    }

                    indexItem.ViewRoles = pageSettings.AuthorizedRoles;
                    indexItem.ModuleViewRoles = row["ViewRoles"].ToString();
                    if (pageSettings.UseUrl)
                    {
                        if (pageSettings.UrlHasBeenAdjustedForFolderSites)
                        {
                            indexItem.ViewPage = pageSettings.UnmodifiedUrl.Replace("~/", string.Empty);
                        }
                        else
                        {
                            indexItem.ViewPage = pageSettings.Url.Replace("~/", string.Empty);
                        }
                        indexItem.UseQueryStringParams = false;
                    }
                    indexItem.FeatureId = htmlFeatureGuid.ToString();
                    indexItem.FeatureName = htmlFeature.FeatureName;
                    indexItem.FeatureResourceFile = htmlFeature.ResourceFile;

                    indexItem.ItemId = Convert.ToInt32(row["ItemID"]);
                    indexItem.ModuleId = Convert.ToInt32(row["ModuleID"]);
                    indexItem.ModuleTitle = row["ModuleTitle"].ToString();
                    indexItem.Title = row["Title"].ToString();
                    // added the remove markup 2010-01-30 because some javascript strings like ]]> were apearing in search results if the content conatined jacvascript
                    indexItem.Content = SecurityHelper.RemoveMarkup(row["Body"].ToString());

                    indexItem.CreatedUtc = Convert.ToDateTime(row["CreatedDate"]);
                    indexItem.LastModUtc = Convert.ToDateTime(row["LastModUtc"]);

                    // lookup publish dates
                    foreach (PageModule pageModule in pageModules)
                    {
                        if (indexItem.ModuleId == pageModule.ModuleId)
                        {
                            indexItem.PublishBeginDate = pageModule.PublishBeginDate;
                            indexItem.PublishEndDate = pageModule.PublishEndDate;
                        }
                    }

                    IndexHelper.RebuildIndex(indexItem, indexPath);

                    log.Debug("Indexed " + indexItem.Title);

                }
            }
            catch (System.Data.Common.DbException ex)
            {
                log.Error(ex);
            }
        }
예제 #6
0
        private void LoadSettings()
        {
            pageId = WebUtils.ParseInt32FromQueryString("pageid", -1);
            moduleId = WebUtils.ParseInt32FromQueryString("mid", -1);

            //if (Request.Form.Count > 0)
            //{
            //    submittedContent = Server.UrlDecode(Request.Form.ToString()); // this gets the full content of the post

            //}

            if (Request.Form["html"] != null)
            {
                submittedContent = Request.Form["html"];
                //log.Info("html does = " + Request.Form["html"]);
            }

            //using (Stream s = Request.InputStream)
            //{
            //    using (StreamReader sr = new StreamReader(s))
            //    {
            //        string requestBody = sr.ReadToEnd();
            //        requestBody = Server.UrlDecode(requestBody);
            //        log.Info("requestBody was " + requestBody);
            //        JObject jObj = JObject.Parse(requestBody);
            //        submittedContent = (string)jObj["html"];
            //    }
            //}

            module = GetHtmlModule();

            if (module == null) { return; }

            currentUser = SiteUtils.GetCurrentSiteUser();
            repository = new HtmlRepository();
            moduleSettings = ModuleSettings.GetModuleSettings(module.ModuleId);
            config = new HtmlConfiguration(moduleSettings);

            enableContentVersioning = config.EnableContentVersioning;

            if ((CurrentSite.ForceContentVersioning) || (WebConfigSettings.EnforceContentVersioningGlobally))
            {
                enableContentVersioning = true;
            }

            userCanOnlyEditAsDraft = UserCanOnlyEditModuleAsDraft(module.ModuleId, HtmlContent.FeatureGuid);

            if ((WebConfigSettings.EnableContentWorkflow) && (CurrentSite.EnableContentWorkflow))
            {
                workInProgress = ContentWorkflow.GetWorkInProgress(module.ModuleGuid);
            }

            if (workInProgress != null)
            {
                switch (workInProgress.Status)
                {
                    case ContentWorkflowStatus.Draft:

                        //there is a draft version currently available, therefore dont allow the non draft version to be edited:

                        if (ViewMode == PageViewMode.WorkInProgress)
                        {
                            editDraft = true;
                        }

                        break;

                    case ContentWorkflowStatus.ApprovalRejected:
                        //rejected content - allow update as draft only

                        if (ViewMode == PageViewMode.WorkInProgress)
                        {
                            editDraft = true;
                        }
                        break;

                    case ContentWorkflowStatus.AwaitingApproval:
                        //pending approval - dont allow any edited:
                        // 2010-01-18 let editors update the draft if they want to before approving it.
                        editDraft = !userCanOnlyEditAsDraft;
                        break;
                }
            }

            //for (int i = 0; i < Request.QueryString.Count; i++)
            //{
            //    log.Info(Request.QueryString.GetKey(i) + " query param = " + Request.QueryString.Get(i));
            //}

            //if (Request.Form["c"] != null)
            //{
            //    submittedContent = Request.Form["c"];
            //    log.Info("c does = " + Request.Form["c"]);
            //}

            // this shows that a large html content post appears as multiple params
            //for (int i = 0; i < Request.Form.Count; i++)
            //{
            //    log.Info(Request.Form.GetKey(i) + " form param " + i.ToInvariantString() + " = " + Request.Form.Get(i));
            //}
        }
예제 #7
0
        private void LoadSettings()
        {
            ScriptConfig.IncludeColorBox = true;
            repository = new HtmlRepository();

            try
            {
                // this keeps the action from changing during ajax postback in folder based sites
                SiteUtils.SetFormAction(Page, Request.RawUrl);
            }
            catch (MissingMethodException)
            {
                //this method was introduced in .NET 3.5 SP1
            }

            virtualRoot = WebUtils.GetApplicationRoot();

            currentUser = SiteUtils.GetCurrentSiteUser();
            timeOffset = SiteUtils.GetUserTimeOffset();
            lnkCancel.NavigateUrl = SiteUtils.GetCurrentPageUrl();

            module = GetHtmlModule();

            if (module == null)
            {
                SiteUtils.RedirectToAccessDeniedPage(this);
                return;

            }

            if (module.ModuleTitle.Length == 0)
            {
                //this is not persisted just used for display if there is no title
                module.ModuleTitle = Resource.EditHtmlSettingsLabel;
            }

            heading.Text = Server.HtmlEncode(module.ModuleTitle);

            userCanEdit = UserCanEdit(moduleId);
            userCanEditAsDraft = UserCanOnlyEditModuleAsDraft(moduleId, HtmlContent.FeatureGuid);

            divExcludeFromRecentContent.Visible = userCanEdit;

            pageSize = config.VersionPageSize;
            enableContentVersioning = config.EnableContentVersioning;

            if ((siteSettings.ForceContentVersioning) || (WebConfigSettings.EnforceContentVersioningGlobally))
            {
                enableContentVersioning = true;
            }

            if ((WebUser.IsAdminOrContentAdmin) || (SiteUtils.UserIsSiteEditor())) { isAdmin = true; }

            edContent.WebEditor.ToolBar = ToolBar.FullWithTemplates;

            if (moduleSettings.Contains("HtmlEditorHeightSetting"))
            {
                edContent.WebEditor.Height = Unit.Parse(moduleSettings["HtmlEditorHeightSetting"].ToString());
            }

            divHistoryDelete.Visible = (enableContentVersioning && isAdmin);

            pnlHistory.Visible = enableContentVersioning;

             SetupScript();

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

            if ((!userCanEdit) && (userCanEditAsDraft))
            {
                btnUpdate.Visible = false;
                btnUpdateDraft.Visible = true;
            }

            btnUpdateDraft.Text = Resource.EditHtmlUpdateDraftButton;

            if ((WebConfigSettings.EnableContentWorkflow) && (siteSettings.EnableContentWorkflow))
            {
                workInProgress = ContentWorkflow.GetWorkInProgress(this.module.ModuleGuid);
                //bool draftOnlyAccess = UserCanOnlyEditModuleAsDraft(moduleId);

                if (workInProgress != null)
                {
                    // let editors toggle between draft and live view in the editor
                    if (userCanEdit) { SetupWorkflowControls(true); }

                    switch (workInProgress.Status)
                    {
                        case ContentWorkflowStatus.Draft:

                            //there is a draft version currently available, therefore dont allow the non draft version to be edited:
                            btnUpdateDraft.Visible = true;
                            btnUpdate.Visible = false;
                            if (ViewMode == PageViewMode.WorkInProgress)
                            {
                                //litModuleTitle.Text += " - " + Resource.ApprovalProcessStatusDraft;
                                heading.Text = string.Format(CultureInfo.InvariantCulture, Resource.DraftFormat, module.ModuleTitle);
                                lblContentStatusLabel.SetOrAppendCss("wf-draft"); //JOE DAVIS
                                if (userCanEdit) { btnPublishDraft.Visible = true; }
                            }

                            break;

                        case ContentWorkflowStatus.ApprovalRejected:
                            //rejected content - allow update as draft only
                            btnUpdateDraft.Visible = true;
                            btnUpdate.Visible = false;
                            if (ViewMode == PageViewMode.WorkInProgress)
                            {
                                //litModuleTitle.Text += " - " + Resource.ApprovalProcessStatusRejected;
                                heading.Text = string.Format(CultureInfo.InvariantCulture, Resource.ContentRejectedFormat, module.ModuleTitle);
                                lblContentStatusLabel.SetOrAppendCss("wf-rejected"); //JOE DAVIS
                            }
                            break;

                        case ContentWorkflowStatus.AwaitingApproval:
                            //pending approval - dont allow any edited:
                            // 2010-01-18 let editors update the draft if they want to before approving it.
                            btnUpdateDraft.Visible = userCanEdit;

                            btnUpdate.Visible = false;
                            if (ViewMode == PageViewMode.WorkInProgress)
                            {
                                //litModuleTitle.Text += " - " + Resource.ApprovalProcessStatusAwaitingApproval;
                                heading.Text = string.Format(CultureInfo.InvariantCulture, Resource.ContentAwaitingApprovalFormat, module.ModuleTitle);
                                lblContentStatusLabel.SetOrAppendCss("wf-awaitingapproval"); //JOE DAVIS
                            }
                            break;
                        //JOE DAVIS
                        case ContentWorkflowStatus.AwaitingPublishing:
                            //pending publishing - allow editors, publishers, admin to update before publishing
                            btnUpdateDraft.Visible = userCanEdit;

                            btnUpdate.Visible = false;

                            if (ViewMode == PageViewMode.WorkInProgress)
                            {
                                heading.Text = string.Format(CultureInfo.InvariantCulture, Resource.ContentAwaitingPublishingFormat, module.ModuleTitle);
                                lblContentStatusLabel.SetOrAppendCss("wf-awaitingpublishing");
                            }
                            break;
                    }
                }
                else
                {
                    //workInProgress is null there is no draft
                    if (userCanEdit)
                    {
                        btnUpdateDraft.Text = Resource.CreateDraftButton;
                        btnUpdateDraft.Visible = true;
                    }

                }

                if ((userCanEdit) && (ViewMode == PageViewMode.Live))
                {
                    btnUpdateDraft.Visible = false;
                    btnUpdate.Visible = true;
                }

            }

            AddClassToBody("htmledit");
        }
예제 #8
0
        /// <summary>
        /// wp.getPages method
        /// </summary>
        /// <param name="blogId">
        /// blogID in string format
        /// </param>
        /// <param name="userName">
        /// login username
        /// </param>
        /// <param name="password">
        /// login password
        /// </param>
        /// <returns>
        /// a list of pages
        /// </returns>
        internal List<MWAPage> GetPages(string blogId, string userName, string password)
        {
            List<MWAPage> allPages = new List<MWAPage>();

            HtmlRepository repository = new HtmlRepository();

            using (IDataReader reader = repository.GetHtmlForMetaWeblogApi(siteSettings.SiteId))
            {
                while (reader.Read())
                {
                    MWAPage p = new MWAPage();
                    p.description = reader["Body"].ToString();
                    p.link = FormatPageUrl(Convert.ToInt32(reader["PageID"]), reader["Url"].ToString(), Convert.ToBoolean(reader["UseUrl"]));

                    // adjust from utc to user time zone
                    if (reader["PublishBeginDate"] != DBNull.Value)
                    {
                        p.pageUtcDate = Convert.ToDateTime(reader["PublishBeginDate"]);
                        p.pageDate = Convert.ToDateTime(reader["PublishBeginDate"]).ToLocalTime(timeZone);
                        //p.pageDate = TimeZoneInfo.ConvertTimeFromUtc(DateTime.SpecifyKind(Convert.ToDateTime(reader["PublishBeginDate"]), DateTimeKind.Utc), timeZone);
                    }
                    else
                    {
                        p.pageUtcDate = DateTime.UtcNow;
                        p.pageDate = DateTime.UtcNow.AddMinutes(-5).ToLocalTime(timeZone);
                    }

                    p.pageID = reader["PageGuid"].ToString().ToLowerInvariant();
                    p.pageParentID = reader["ParentGuid"].ToString().ToLowerInvariant();

                    p.pageOrder = Convert.ToInt32(reader["PageOrder"]).ToInvariantString();

                    p.title = reader["PageName"].ToString();
                    p.pageEditRoles = reader["EditRoles"].ToString();
                    p.moduleEditRoles = reader["AuthorizedEditRoles"].ToString();

                    bool allowComments = Convert.ToBoolean(reader["EnableComments"]);
                    if (allowComments)
                    {
                        p.commentPolicy = "1";
                    }
                    else
                    {
                        p.commentPolicy = "0";
                    }

                    bool isDraft = Convert.ToBoolean(reader["IsPending"]);
                    if (isDraft)
                    {
                        p.published = "draft";
                    }
                    else
                    {
                        p.published = "publish";
                    }

                    allPages.Add(p);

                }
            }

            List<MWAPage> allowedPages = new List<MWAPage>();

            foreach (MWAPage p in allPages)
            {
                // filter out all except the first html instance on the page
                if (Contains(allowedPages, p.pageID)) { continue; }
                if (UserCanEdit(p)) { allowedPages.Add(p); }
            }

            return allowedPages;
        }
예제 #9
0
        /// <summary>
        /// wp.getPage method
        /// </summary>
        /// <param name="blogId">
        /// blogID in string format
        /// </param>
        /// <param name="pageId">
        /// page guid in string format
        /// </param>
        /// <param name="userName">
        /// login username
        /// </param>
        /// <param name="password">
        /// login password
        /// </param>
        /// <returns>
        /// struct with post details
        /// </returns>
        internal MWAPage GetPage(string blogId, string pageId, string userName, string password)
        {
            var p = new MWAPage();
            PageSettings page = CacheHelper.GetPage(new Guid(pageId));

            if (page.PageId == -1)
            { //doesn't exist
                throw new MetaWeblogException("11", MetaweblogResources.PageNotFound);
            }

            Module m  = GetFirstCenterPaneHtmlModule(page);

            if (m == null)
            {
                throw new MetaWeblogException("11", MetaweblogResources.ContentInstanceNotFound);
            }

            HtmlRepository repository = new HtmlRepository();
            HtmlContent html = repository.Fetch(m.ModuleId);

            // html does not immediately exist as soon as module is added to the page
            // it is created upon first edit if it does not so we need to check for null
            if (html != null)
            {
                p.description = html.Body;

            }

            p.pageUtcDate = page.LastModifiedUtc;
            p.pageDate = page.LastModifiedUtc.ToLocalTime(timeZone);
            if (page.UrlHasBeenAdjustedForFolderSites)
            {
                p.link = FormatPageUrl(page.PageId, page.UnmodifiedUrl, page.UseUrl);
            }
            else
            {
                p.link = FormatPageUrl(page.PageId, page.Url, page.UseUrl);
            }

            p.pageID = page.PageGuid.ToString();
            p.pageParentID = page.ParentGuid.ToString();

            if (page.ParentGuid != Guid.Empty)
            {
                PageSettings parentPage = new PageSettings(page.ParentGuid);
                p.parentTitle = parentPage.PageName;
            }
            else
            {
                p.pageParentID = string.Empty; // we don't want to pass Guid.Empty it causes problems in wlw
            }

            p.pageOrder = page.PageOrder.ToInvariantString();

            // generally module title and page name should be the same
            // except on the home page since we don't want to change the pagename of the home page
            // to match th emodule title we must return the module title when getting the page for edit purposes
            p.title = m.ModuleTitle;
            p.pageEditRoles = page.EditRoles;
            p.moduleEditRoles = m.AuthorizedEditRoles;

            if (page.EnableComments)
            {
                p.commentPolicy = "1";
            }
            else
            {
                p.commentPolicy = "2";
            }

            if (!UserCanEdit(p))
            {
                throw new MetaWeblogException("11", "User doesn't have permission on this content");
            }

            return p;
        }
예제 #10
0
        /// <summary>
        /// Edits the page.
        /// </summary>
        /// <param name="blogId">
        /// The blog id.
        /// </param>
        /// <param name="pageId">
        /// The page id.
        /// </param>
        /// <param name="userName">
        /// The user name.
        /// </param>
        /// <param name="password">
        /// The password.
        /// </param>
        /// <param name="mwaPage">
        /// The m page.
        /// </param>
        /// <param name="publish">
        /// The publish.
        /// </param>
        /// <returns>
        /// The edit page.
        /// </returns>
        internal bool EditPage(string blogId, string pageId, string userName, string password, MWAPage mwaPage, bool publish)
        {
            if ((string.IsNullOrEmpty(pageId))||(pageId.Length != 36))
            {
                throw new MetaWeblogException("11", MetaweblogResources.PageNotFound);
            }

            PageSettings page = CacheHelper.GetPage(new Guid(pageId));

            if (page.PageId == -1)
            { //doesn't exist
                throw new MetaWeblogException("11", MetaweblogResources.PageNotFound);
            }

            if (page.SiteId != siteSettings.SiteId)
            { //doesn't exist
                throw new MetaWeblogException("11", MetaweblogResources.PageNotFound);
            }

            //if (!publish)
            //{
            //    throw new MetaWeblogException("11", "Sorry draft pages are not supported through this API.");
            //}

            Module m = GetFirstCenterPaneHtmlModule(page);

            if (m == null)
            {
                throw new MetaWeblogException("11", MetaweblogResources.ContentInstanceNotFound);
            }

            if (!UserCanEdit(page, m))
            {
                throw new MetaWeblogException("11", MetaweblogResources.AccessDenied);
            }

            PageSettings parentPage = null;
            Hashtable moduleSettings = ModuleSettings.GetModuleSettings(m.ModuleId);
            HtmlConfiguration config = new HtmlConfiguration(moduleSettings);

            HtmlRepository repository = new HtmlRepository();
            HtmlContent html = repository.Fetch(m.ModuleId);

            if (html == null)
            {
                html = new HtmlContent();
                html.ModuleId = m.ModuleId;
                html.ModuleGuid = m.ModuleGuid;
            }

            bool titleChanged = (m.ModuleTitle != mwaPage.title);
            // updated 2011-11-30 don't change page name for existing pages
            // only update the module title
            // avoid changing the home page name
            // while most content pages should have the module title the same as the page name for best seo
            // this is usually not the case for the home page, ie the content is not titled "home"
            //if (!IsHomePage(page.PageId))
            //{
            //    page.PageName = mwaPage.title;
            //}

            if (titleChanged)
            {
                m.ModuleTitle = mwaPage.title;
                m.Save();

            }

            html.Body = mwaPage.description;
            if ((mwaPage.mt_keywords != null) &&(mwaPage.mt_keywords.Length > 0))
            {
                page.PageMetaKeyWords = mwaPage.mt_keywords;
            }

            bool needToClearSiteMapCache = false;
            bool pageOrderChanged = false;
            if ((mwaPage.pageOrder != null)&&(mwaPage.pageOrder.Length > 0))
            {
                int newPageOrder = Convert.ToInt32(mwaPage.pageOrder);
                if (page.PageOrder != newPageOrder)
                {
                    page.PageOrder = newPageOrder;
                    needToClearSiteMapCache = true;
                    pageOrderChanged = true;
                }
            }

            bool makeDraft = !publish;

            if (page.IsPending != makeDraft)
            {
                page.IsPending = makeDraft;
                needToClearSiteMapCache = true;
            }

            if ((mwaPage.pageParentID != null) &&(mwaPage.pageParentID.Length == 36))
            {
                Guid parentGuid = new Guid(mwaPage.pageParentID);

                if (page.PageGuid == parentGuid)
                {
                    throw new MetaWeblogException("11", MetaweblogResources.PageCantBeItsOwnParent);
                }

                // if parent pageid hasn't changed no need to doo anything
                if (parentGuid != page.ParentGuid)
                {
                    if (parentGuid == Guid.Empty)
                    {
                        if (UserCanCreateRootLevelPages())
                        {
                            page.ParentId = -1;
                            page.PageGuid = Guid.Empty;
                            needToClearSiteMapCache = true;
                        }
                        else
                        {
                            throw new MetaWeblogException("11", MetaweblogResources.NotAllowedToCreateRootPages);
                        }
                    }
                    else
                    {
                        parentPage = new PageSettings(parentGuid);

                        if (parentPage.SiteId != siteSettings.SiteId)
                        {
                            throw new MetaWeblogException("11", MetaweblogResources.ParentPageNotFound);
                        }

                        if (
                            (parentPage.PageId > -1)
                            && (parentPage.PageId != page.PageId) // page cannot be its own parent
                            && (parentPage.ParentId != page.PageId) // a child of the page cannot become its parent
                            )
                        {
                            // parent page exists

                            //verify user can create pages below parent
                            if (!UserCanCreateChildPages(parentPage))
                            {
                                throw new MetaWeblogException("11", MetaweblogResources.NotAllowedParentPage);
                            }

                            // descendant of page (grandchildren cannot become parent)
                            // so make sure selected parent is not a descendant of the current page
                            if (IsValidParentPage(page, parentPage))
                            {
                                page.ParentId = parentPage.PageId;
                                page.PageGuid = parentPage.PageGuid;
                                needToClearSiteMapCache = true;
                            }
                            else
                            {
                                throw new MetaWeblogException("11", MetaweblogResources.DescendentParentsNotAllowed);
                            }

                        }
                    }
                }
            }

            // keep verison history if enabled
            bool enableContentVersioning = config.EnableContentVersioning;

            if ((siteSettings.ForceContentVersioning) || (WebConfigSettings.EnforceContentVersioningGlobally))
            {
                enableContentVersioning = true;
            }

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

            html.LastModUserGuid = siteUser.UserGuid;
            html.LastModUtc = DateTime.UtcNow;
            page.LastModifiedUtc = DateTime.UtcNow;
            html.ModuleGuid = m.ModuleGuid;

            html.ContentChanged += new ContentChangedEventHandler(html_ContentChanged);

            repository.Save(html);

            CacheHelper.ClearModuleCache(m.ModuleId);

            switch (mwaPage.commentPolicy)
            {
                //closed
                case "0":
                case "2":
                    page.EnableComments = false;
                    break;
                // open
                case "1":
                    // if the post was previously closed to comments
                    // re-open it using the default allowed days
                    page.EnableComments = true;

                    break;
                //else unspecified, no change
            }

            if (page.UrlHasBeenAdjustedForFolderSites)
            {
                page.Url = page.UnmodifiedUrl;
            }

            page.Save();

            if (pageOrderChanged)
            {
                if ((parentPage == null) && (page.ParentGuid != Guid.Empty))
                {
                    parentPage = new PageSettings(page.ParentGuid);
                }

            }

            if (parentPage != null)
            {
                parentPage.ResortPages();
            }

            if (needToClearSiteMapCache)
            {
                CacheHelper.ResetSiteMapCache(siteSettings.SiteId);
            }

            SiteUtils.QueueIndexing();

            return true;
        }
예제 #11
0
        /// <summary>
        /// wp.newPage method
        /// </summary>
        /// <param name="blogId">blogID in string format</param>
        /// <param name="userName">login username</param>
        /// <param name="password">login password</param>
        /// <param name="mwaPage">The mwa page.</param>
        /// <param name="publish">if set to <c>true</c> [publish].</param>
        /// <returns>The new page.</returns>
        internal string NewPage(string blogId, string userName, string password, MWAPage mwaPage, bool publish)
        {
            PageSettings page = new PageSettings();
            PageSettings parentPage = null;

            Guid parentGuid = Guid.Empty;
            if ((mwaPage.pageParentID != null)&&(mwaPage.pageParentID.Length == 36))
            {
                parentGuid = new Guid(mwaPage.pageParentID);
            }

            if (parentGuid == Guid.Empty) //root level page
            {
                if (!UserCanCreateRootLevelPages())
                {
                    throw new MetaWeblogException("11", MetaweblogResources.NotAllowedToCreateRootPages);
                }

                // TODO: promote these to site settings?
                //page.AuthorizedRoles = WebConfigSettings.DefaultPageRoles;
                //page.EditRoles = WebConfigSettings.DefaultRootPageEditRoles;
                //page.CreateChildPageRoles = WebConfigSettings.DefaultRootPageCreateChildPageRoles;

                page.AuthorizedRoles = siteSettings.DefaultRootPageViewRoles;
                page.EditRoles = siteSettings.DefaultRootPageEditRoles;
                page.CreateChildPageRoles = siteSettings.DefaultRootPageCreateChildPageRoles;
            }
            else
            {
                parentPage = new PageSettings(parentGuid);

                if (parentPage.PageId == -1)
                {
                    throw new MetaWeblogException("11", MetaweblogResources.ParentPageNotFound);
                }

                if (parentPage.SiteId != siteSettings.SiteId)
                {
                    throw new MetaWeblogException("11", MetaweblogResources.ParentPageNotFound);
                }

                if (!UserCanCreateChildPages(parentPage))
                {
                    throw new MetaWeblogException("11", MetaweblogResources.NotAllowedParentPage);
                }
            }

            if (parentPage != null)
            {
                page.ParentId = parentPage.PageId;
                page.ParentGuid = parentPage.PageGuid;
                page.PageOrder = PageSettings.GetNextPageOrder(siteSettings.SiteId, parentPage.PageId);

                // by default inherit settings from parent
                page.AuthorizedRoles = parentPage.AuthorizedRoles;
                page.EditRoles = parentPage.EditRoles;
                page.DraftEditOnlyRoles = parentPage.DraftEditOnlyRoles;
                page.CreateChildPageRoles = parentPage.CreateChildPageRoles;
                page.CreateChildDraftRoles = parentPage.CreateChildDraftRoles;
            }

            if ((mwaPage.pageOrder != null) && (mwaPage.pageOrder.Length > 0))
            {
                 page.PageOrder = Convert.ToInt32(mwaPage.pageOrder);
            }

            page.SiteId = siteSettings.SiteId;
            page.SiteGuid = siteSettings.SiteGuid;
            page.IsPending = !publish;

            page.PageName = mwaPage.title;
            //page.PageTitle = mwaPage.title; // this was the override page title it should not be set here
            if ((mwaPage.mt_keywords != null) && (mwaPage.mt_keywords.Length > 0))
            {
                page.PageMetaKeyWords = mwaPage.mt_keywords;
            }

            if (WebConfigSettings.AutoGeneratePageMetaDescriptionForMetaweblogNewPages)
            {
                page.PageMetaDescription = UIHelper.CreateExcerpt(mwaPage.description, WebConfigSettings.MetaweblogGeneratedMetaDescriptionMaxLength);
            }

            //if (WebConfigSettings.ShowUseUrlSettingInPageSettings)
            //{

            //}

            string friendlyUrlString = SiteUtils.SuggestFriendlyUrl(page.PageName, siteSettings);
            page.Url = "~/" + friendlyUrlString;
            page.UseUrl = true;

            switch (mwaPage.commentPolicy)
            {
                // open
                case "1":
                    // if the post was previously closed to comments
                    // re-open it using the default allowed days
                    page.EnableComments = true;

                    break;

                //closed
                case "0":
                case "2":
                default:
                    page.EnableComments = false;
                    break;

            }

            // I'm not sure we should support the page created event handler here, people may do redirects there
            // that would interupt our next steps
            // maybe need a config setting to decide

            // page.PageCreated += new PageCreatedEventHandler(PageCreated);

            page.Save();

            FriendlyUrl newFriendlyUrl = new FriendlyUrl();
            newFriendlyUrl.SiteId = siteSettings.SiteId;
            newFriendlyUrl.SiteGuid = siteSettings.SiteGuid;
            newFriendlyUrl.PageGuid = page.PageGuid;
            newFriendlyUrl.Url = friendlyUrlString;
            newFriendlyUrl.RealUrl = "~/Default.aspx?pageid=" + page.PageId.ToInvariantString();
            newFriendlyUrl.Save();

            // create html module in center pane
            ModuleDefinition moduleDefinition = new ModuleDefinition(HtmlContent.FeatureGuid);
            Module m = new Module();
            m.SiteId = siteSettings.SiteId;
            m.SiteGuid = siteSettings.SiteGuid;
            m.ModuleDefId = moduleDefinition.ModuleDefId;
            m.FeatureGuid = moduleDefinition.FeatureGuid;
            m.Icon = moduleDefinition.Icon;
            m.CacheTime = moduleDefinition.DefaultCacheTime;
            m.PageId = page.PageId;
            m.ModuleTitle = page.PageTitle;
            m.PaneName = "contentpane";
            m.CreatedByUserId = siteUser.UserId;
            m.ShowTitle = WebConfigSettings.ShowModuleTitlesByDefault;
            m.HeadElement = WebConfigSettings.ModuleTitleTag;
            m.ModuleOrder = 1;
            m.Save();

            HtmlRepository repository = new HtmlRepository();
            HtmlContent html = new HtmlContent();
            html.ModuleId = m.ModuleId;
            html.ModuleGuid = m.ModuleGuid;
            html.Body = mwaPage.description;
            //html.CreatedBy = siteUser.UserId;
            html.UserGuid = siteUser.UserGuid;
            html.CreatedDate = DateTime.UtcNow;
            html.LastModUserGuid = siteUser.UserGuid;
            html.LastModUtc = DateTime.UtcNow;

            html.ContentChanged += new ContentChangedEventHandler(html_ContentChanged);

            repository.Save(html);

            mojoPortal.SearchIndex.IndexHelper.RebuildPageIndexAsync(page);
            SiteUtils.QueueIndexing();

            CacheHelper.ResetSiteMapCache(siteSettings.SiteId);

            return page.PageGuid.ToString();
        }