private void Save() { if (blog == null) { blog = new Blog(itemId); if ((blog.ItemId > -1) && (blog.ModuleId != moduleId)) { SiteUtils.RedirectToAccessDeniedPage(this); return; } } Module module = GetModule(moduleId, Blog.FeatureGuid); if (module == null) { return; } if (currentUser == null) { return; } blog.UserGuid = currentUser.UserGuid; blog.LastModUserGuid = currentUser.UserGuid; blog.ContentChanged += new ContentChangedEventHandler(blog_ContentChanged); blog.ModuleId = moduleId; blog.ModuleGuid = module.ModuleGuid; DateTime localTime = DateTime.Parse(dpBeginDate.Text); if (timeZone != null) { blog.StartDate = localTime.ToUtc(timeZone); } else { blog.StartDate = localTime.AddHours(-timeOffset); } if (dpEndDate.Text.Length == 0) { blog.EndDate = DateTime.MaxValue; } else { DateTime localEndTime = DateTime.Parse(dpEndDate.Text); if (timeZone != null) { blog.EndDate = localEndTime.ToUtc(timeZone); } else { blog.EndDate = localEndTime.AddHours(-timeOffset); } } blog.Title = txtTitle.Text; blog.SubTitle = txtSubTitle.Text; blog.Location = txtLocation.Text; blog.Description = edContent.Text; blog.Excerpt = edExcerpt.Text; blog.UserName = Context.User.Identity.Name; blog.IncludeInFeed = this.chkIncludeInFeed.Checked; blog.IsPublished = chkIsPublished.Checked; int allowComentsForDays = -1; int.TryParse(ddCommentAllowedForDays.SelectedValue, out allowComentsForDays); blog.AllowCommentsForDays = allowComentsForDays; blog.MetaDescription = txtMetaDescription.Text; blog.MetaKeywords = txtMetaKeywords.Text; blog.ShowDownloadLink = chkShowDownloadLink.Checked; blog.UseBingMap = chkUseBing.Checked; blog.MapType = ((GMapTypeSetting)MapTypeControl).GetValue(); int mapZoom = 13; int.TryParse(((GMapZoomLevelSetting)ZoomLevelControl).GetValue(), out mapZoom); blog.MapZoom = mapZoom; blog.MapHeight = txtMapHeight.Text; blog.MapWidth = txtMapWidth.Text; blog.ShowMapOptions = chkShowMapOptions.Checked; blog.ShowZoomTool = chkShowMapZoom.Checked; blog.ShowLocationInfo = chkShowMapBalloon.Checked; blog.UseDrivingDirections = chkShowMapDirections.Checked; blog.IncludeInSearch = chkIncludeInSearchIndex.Checked; blog.ExcludeFromRecentContent = chkExcludeFromRecentContent.Checked; blog.IncludeInSiteMap = chkIncludeInSiteMap.Checked; blog.ShowAuthorName = chkShowAuthorName.Checked; blog.ShowAuthorAvatar = chkShowAuthorAvatar.Checked; blog.ShowAuthorBio = chkShowAuthorBio.Checked; blog.IncludeInNews = chkIncludeInNews.Checked; blog.PubName = txtPublicationName.Text; blog.PubLanguage = txtPubLanguage.Text; blog.PubAccess = config.PublicationAccess; blog.PubGenres = txtPubGenres.Text; blog.PubGeoLocations = txtPubGeoLocations.Text; blog.PubKeyWords = txtPubKeyWords.Text; blog.PubStockTickers = txtPubStockTickers.Text; blog.HeadlineImageUrl = txtHeadlineImage.Text; if (blog.HeadlineImageUrl.Length > 0) { imgPreview.ImageUrl = blog.HeadlineImageUrl; } blog.IncludeImageInExcerpt = chkIncludeImageInExcerpt.Checked; if (txtItemUrl.Text.Length == 0) { txtItemUrl.Text = SuggestUrl(); } String friendlyUrlString = SiteUtils.RemoveInvalidUrlChars(txtItemUrl.Text.Replace("~/", String.Empty)); FriendlyUrl friendlyUrl = new FriendlyUrl(siteSettings.SiteId, friendlyUrlString); if ( ((friendlyUrl.FoundFriendlyUrl) && (friendlyUrl.PageGuid != blog.BlogGuid)) && (blog.ItemUrl != txtItemUrl.Text) ) { lblError.Text = BlogResources.PageUrlInUseBlogErrorMessage; cancelRedirect = true; return; } if (!friendlyUrl.FoundFriendlyUrl) { if (WebPageInfo.IsPhysicalWebPage("~/" + friendlyUrlString)) { lblError.Text = BlogResources.PageUrlInUseBlogErrorMessage; cancelRedirect = true; return; } } string oldUrl = blog.ItemUrl.Replace("~/", string.Empty); string newUrl = SiteUtils.RemoveInvalidUrlChars(txtItemUrl.Text.Replace("~/", string.Empty)); blog.ItemUrl = "~/" + newUrl; if (enableContentVersioning) { blog.CreateHistory(siteSettings.SiteGuid); } blog.Save(); //added by suresh UploadCoverImage(blog.ItemId.ToInvariantString()); //added above by suresh if (!friendlyUrl.FoundFriendlyUrl) { if ((friendlyUrlString.Length > 0)&&(!WebPageInfo.IsPhysicalWebPage("~/" + friendlyUrlString))) { FriendlyUrl newFriendlyUrl = new FriendlyUrl(); newFriendlyUrl.SiteId = siteSettings.SiteId; newFriendlyUrl.SiteGuid = siteSettings.SiteGuid; newFriendlyUrl.PageGuid = blog.BlogGuid; newFriendlyUrl.Url = friendlyUrlString; newFriendlyUrl.RealUrl = "~/Blog/ViewPost.aspx?pageid=" + pageId.ToInvariantString() + "&mid=" + blog.ModuleId.ToInvariantString() + "&ItemID=" + blog.ItemId.ToInvariantString(); newFriendlyUrl.Save(); } //if post was renamed url will change, if url changes we need to redirect from the old url to the new with 301 if ((oldUrl.Length > 0) && (newUrl.Length > 0) && (!SiteUtils.UrlsMatch(oldUrl, newUrl)) && BlogConfiguration.Create301OnPostRename) { //worry about the risk of a redirect loop if the page is restored to the old url again // don't create it if a redirect for the new url exists if ( (!RedirectInfo.Exists(siteSettings.SiteId, oldUrl)) && (!RedirectInfo.Exists(siteSettings.SiteId, newUrl)) ) { RedirectInfo redirect = new RedirectInfo(); redirect.SiteGuid = siteSettings.SiteGuid; redirect.SiteId = siteSettings.SiteId; redirect.OldUrl = oldUrl; redirect.NewUrl = newUrl; redirect.Save(); } // since we have created a redirect we don't need the old friendly url FriendlyUrl oldFriendlyUrl = new FriendlyUrl(siteSettings.SiteId, oldUrl); if ((oldFriendlyUrl.FoundFriendlyUrl) && (oldFriendlyUrl.PageGuid == blog.BlogGuid)) { FriendlyUrl.DeleteUrl(oldFriendlyUrl.UrlId); } } } // new item posted so ping services if ((itemId == -1) && (blog.IsPublished) && (blog.StartDate <= DateTime.UtcNow)) { QueuePings(); } CurrentPage.UpdateLastModifiedTime(); // friendly feed urls are no longer needed since all params have been combined into 1 param // //String blogFriendlyUrl = "blog" + blog.ModuleId.ToInvariantString() + "rss.aspx"; //if (!FriendlyUrl.Exists(siteSettings.SiteId, blogFriendlyUrl)) //{ // FriendlyUrl rssUrl = new FriendlyUrl(); // rssUrl.SiteId = siteSettings.SiteId; // rssUrl.SiteGuid = siteSettings.SiteGuid; // rssUrl.PageGuid = blog.ModuleGuid; // rssUrl.Url = blogFriendlyUrl; // rssUrl.RealUrl = "~/Blog/RSS.aspx?pageid=" + pageId.ToInvariantString() // + "&mid=" + blog.ModuleId.ToInvariantString(); // rssUrl.Save(); //} Blog.DeleteItemCategories(blog.ItemId); // Mono doesn't see this in update panel // so help find it if (chkCategories == null) { log.Error("chkCategories was null"); chkCategories = (CheckBoxList)UpdatePanel1.FindControl("chkCategories"); } foreach (ListItem listItem in this.chkCategories.Items) { if (listItem.Selected) { Int32 categoryId; if (Int32.TryParse(listItem.Value, out categoryId)) { Blog.AddItemCategory(blog.ItemId, categoryId); } } } //CacheHelper.TouchCacheDependencyFile(cacheDependencyKey); CacheHelper.ClearModuleCache(moduleId); SiteUtils.QueueIndexing(); }
void dlRedirects_ItemCommand(object source, DataListCommandEventArgs e) { Guid rowGuid = new Guid(dlRedirects.DataKeys[e.Item.ItemIndex].ToString()); RedirectInfo redirect = new RedirectInfo(rowGuid); switch (e.CommandName) { case "edit": dlRedirects.EditItemIndex = e.Item.ItemIndex; BindGrid(); break; case "apply": TextBox txtGridOldUrl = (TextBox)e.Item.FindControl("txtGridOldUrl"); TextBox txtGridNewUrl = (TextBox)e.Item.FindControl("txtGridNewUrl"); if ( ((txtGridOldUrl != null) && (txtGridOldUrl.Text.Length > 0)) && ((txtGridNewUrl != null) && (txtGridNewUrl.Text.Length > 0)) ) { redirect.OldUrl = txtGridOldUrl.Text; redirect.NewUrl = txtGridNewUrl.Text; redirect.Save(); WebUtils.SetupRedirect(this, Request.RawUrl); } break; case "delete": RedirectInfo.Delete(rowGuid); WebUtils.SetupRedirect(this, Request.RawUrl); break; case "cancel": WebUtils.SetupRedirect(this, Request.RawUrl); break; } }
void btnAdd_Click(object sender, EventArgs e) { bool isValid = true; if (txtOldUrl.Text.Length == 0) { isValid = false; lblError.Text = Resource.OldUrlRequiredMessage + " "; } if (txtNewUrl.Text.Length == 0) { isValid = false; lblError.Text += Resource.NewUrlRequiredMessage; } if(!isValid){return;} RedirectInfo redirect = new RedirectInfo(); redirect.SiteGuid = siteSettings.SiteGuid; redirect.SiteId = siteSettings.SiteId; redirect.OldUrl = txtOldUrl.Text; redirect.NewUrl = txtNewUrl.Text; redirect.Save(); WebUtils.SetupRedirect(this, Request.RawUrl); }
private bool SavePageData() { Page.Validate("pagesettings"); if (!Page.IsValid) { return false; ; } bool result = true; bool reIndexPage = false; bool clearIndex = false; int newParentID; if (ddPages.Visible) { if (!Int32.TryParse(ddPages.SelectedValue, NumberStyles.Any, CultureInfo.InvariantCulture, out newParentID)) { newParentID = -1; } } else { if (!Int32.TryParse(hdnParentPageId.Value, NumberStyles.Any, CultureInfo.InvariantCulture, out newParentID)) { newParentID = -1; } } PageSettings parentPage = new PageSettings(siteSettings.SiteId, newParentID); pageSettings.ParentGuid = parentPage.PageGuid; pageSettings.SiteId = siteSettings.SiteId; pageSettings.SiteGuid = siteSettings.SiteGuid; if (((pageSettings.PageId != newParentID) && (pageSettings.ParentId != newParentID)) || (pageSettings.PageId == -1)) { pageSettings.ParentId = newParentID; pageSettings.PageOrder = PageSettings.GetNextPageOrder(pageSettings.SiteId, newParentID); } string userName = string.Empty; if (currentUser != null) { userName = currentUser.Name; } if((isAdminOrContentAdmin)&&(!useSeparatePagesForRoles)) { if (rbViewAdminOnly.Checked) { if (pageSettings.AuthorizedRoles != "Admins;") { log.Info("user " + userName + " changed page view roles for " + pageSettings.PageName + " to Admins " + " from ip address " + SiteUtils.GetIP4Address()); pageSettings.AuthorizedRoles = "Admins;"; reIndexPage = true; } } else { string authorizedRoles = chkListAuthRoles.Items.SelectedItemsToSemiColonSeparatedString(); if (pageSettings.AuthorizedRoles != authorizedRoles) { log.Info("user " + userName + " changed page view roles for " + pageSettings.PageName + " to " + authorizedRoles + " from ip address " + SiteUtils.GetIP4Address()); pageSettings.AuthorizedRoles = authorizedRoles; reIndexPage = true; } } if (rbEditAdminOnly.Checked) { pageSettings.EditRoles = "Admins;"; } else { pageSettings.EditRoles = chkListEditRoles.Items.SelectedItemsToSemiColonSeparatedString(); } if (rbCreateChildAdminOnly.Checked) { pageSettings.CreateChildPageRoles = "Admins;"; } else { pageSettings.CreateChildPageRoles = chkListCreateChildPageRoles.Items.SelectedItemsToSemiColonSeparatedString(); } //if (rbDraftEditAdminsOnly.Checked) //{ // pageSettings.DraftEditOnlyRoles = "Admins;"; //} //else //{ pageSettings.DraftEditOnlyRoles = chkDraftEditRoles.Items.SelectedItemsToSemiColonSeparatedString(); //} pageSettings.DraftApprovalRoles = chkDraftApprovalRoles.Items.SelectedItemsToSemiColonSeparatedString(); //joe davis } if (pageId == -1) { if ((!isAdminOrContentAdmin) || (useSeparatePagesForRoles)) { if (newParentID > -1) { // by default inherit permissions from parent pageSettings.AuthorizedRoles = parentPage.AuthorizedRoles; pageSettings.EditRoles = parentPage.EditRoles; pageSettings.CreateChildPageRoles = parentPage.CreateChildPageRoles; pageSettings.DraftEditOnlyRoles = parentPage.DraftEditOnlyRoles; pageSettings.DraftApprovalRoles = parentPage.DraftApprovalRoles; //joe davis if (WebUser.IsInRoles(parentPage.EditRoles)) { pageSettings.EditRoles = parentPage.EditRoles; } else { pageSettings.EditRoles = parentPage.CreateChildPageRoles; } } else { if (WebUser.IsInRoles(siteSettings.RolesThatCanCreateRootPages)) { pageSettings.AuthorizedRoles = siteSettings.DefaultRootPageViewRoles; pageSettings.EditRoles = siteSettings.RolesThatCanCreateRootPages; pageSettings.CreateChildPageRoles = siteSettings.RolesThatCanCreateRootPages; pageSettings.DraftEditOnlyRoles = siteSettings.SiteRootDraftEditRoles; pageSettings.DraftApprovalRoles = siteSettings.SiteRootDraftApprovalRoles; } } } if (currentUser != null) { pageSettings.CreatedBy = currentUser.UserGuid; } pageSettings.CreatedFromIp = SiteUtils.GetIP4Address(); } pageSettings.PageName = SecurityHelper.RemoveMarkup(txtPageName.Text); pageSettings.PageTitle = txtPageTitle.Text; pageSettings.PublishMode = Convert.ToInt32(publishType.GetValue(), CultureInfo.InvariantCulture); if(divPageHeading.Visible) { pageSettings.PageHeading = txtPageHeading.Text; } if(divShowPageHeading.Visible) { pageSettings.ShowPageHeading = chkShowPageHeading.Checked; } if(this.sslIsAvailable) { pageSettings.RequireSsl = chkRequireSSL.Checked; } pageSettings.AllowBrowserCache = chkAllowBrowserCache.Checked; pageSettings.ShowBreadcrumbs = chkShowBreadcrumbs.Checked; pageSettings.ShowChildPageBreadcrumbs = chkShowChildPageBreadcrumbs.Checked; pageSettings.ShowHomeCrumb = chkShowHomeCrumb.Checked; if ((WebConfigSettings.IndexPageMeta) && (pageSettings.PageMetaKeyWords != txtPageKeywords.Text)) { reIndexPage = true; } pageSettings.PageMetaKeyWords = txtPageKeywords.Text; if ((WebConfigSettings.IndexPageMeta) && (pageSettings.PageMetaDescription != txtPageDescription.Text)) { reIndexPage = true; } pageSettings.PageMetaDescription = txtPageDescription.Text; pageSettings.PageMetaEncoding = txtPageEncoding.Text; //pageSettings.PageMetaAdditional = txtPageAdditionalMetaTags.Text; if (divUseUrl.Visible) { pageSettings.UseUrl = chkUseUrl.Checked; } else { pageSettings.UseUrl = (txtUrl.Text.Length > 0); } if (divMenuDesc.Visible) { pageSettings.MenuDescription = txtMenuDesc.Text; } pageSettings.OpenInNewWindow = chkNewWindow.Checked; pageSettings.ShowChildPageMenu = chkShowChildMenu.Checked; pageSettings.IsClickable = chkIsClickable.Checked; pageSettings.IncludeInMenu = chkIncludeInMenu.Checked; pageSettings.IncludeInSiteMap = chkIncludeInSiteMap.Checked; pageSettings.ExpandOnSiteMap = chkExpandOnSiteMap.Checked; pageSettings.IncludeInChildSiteMap = chkIncludeInChildSiteMap.Checked; pageSettings.MenuImage = ddIcons.SelectedValue; pageSettings.HideAfterLogin = chkHideAfterLogin.Checked; pageSettings.IncludeInSearchMap = chkIncludeInSearchEngineSiteMap.Checked; pageSettings.CanonicalOverride = txtCannonicalOverride.Text; pageSettings.EnableComments = chkEnableComments.Checked; pageSettings.BodyCssClass = txtBodyCssClass.Text; pageSettings.MenuCssClass = txtMenuCssClass.Text; pageSettings.LinkRel = txtMenuLinkRelation.Text; if(siteSettings.AllowPageSkins) { //pageSettings.Skin = ddSkins.SelectedValue; pageSettings.Skin = SkinSetting.GetValue(); } if(siteSettings.AllowHideMenuOnPages) { pageSettings.HideMainMenu = chkHideMainMenu.Checked; } String friendlyUrlString = SiteUtils.RemoveInvalidUrlChars(txtUrl.Text.Replace("~/", String.Empty)); //when using extensionless urls lets not allow a trailing slash //if the user enters on in the browser we can resolve it to the page //but its easier if we store them consistently in the db without the / if((friendlyUrlString.EndsWith("/"))&&(!friendlyUrlString.StartsWith("http"))) { friendlyUrlString = friendlyUrlString.Substring(0, friendlyUrlString.Length - 1); } FriendlyUrl friendlyUrl = new FriendlyUrl(siteSettings.SiteId, friendlyUrlString); if ( ((friendlyUrl.FoundFriendlyUrl) && (friendlyUrl.PageGuid != pageSettings.PageGuid)) &&(pageSettings.Url != txtUrl.Text) && (!txtUrl.Text.StartsWith("http")) ) { lblError.Text = Resource.PageUrlInUseErrorMessage; return false; } string oldUrl = pageSettings.Url.Replace("~/", string.Empty); string newUrl = friendlyUrlString; if ((txtUrl.Text.StartsWith("http"))||(txtUrl.Text == "~/")) { pageSettings.Url = txtUrl.Text; } else if(friendlyUrlString.Length > 0) { pageSettings.Url = "~/" + friendlyUrlString; } else if (friendlyUrlString.Length == 0) { pageSettings.Url = string.Empty; } pageSettings.ChangeFrequency = (PageChangeFrequency)Enum.Parse(typeof(PageChangeFrequency), ddChangeFrequency.SelectedValue); pageSettings.SiteMapPriority = ddSiteMapPriority.SelectedValue; if (pageSettings.PageId == -1) { pageSettings.PageCreated += new PageCreatedEventHandler(pageSettings_PageCreated); // no need to index new page until content is added reIndexPage = false; } if ((divIsPending.Visible) && (chkIsPending.Enabled)) { if ((pageSettings.IsPending) && (!chkIsPending.Checked)) { // page changed from draft to published so need to index reIndexPage = true; } if ((!pageSettings.IsPending) && (chkIsPending.Checked)) { //changed from published back to draft //need to clear the search index reIndexPage = false; clearIndex = true; } pageSettings.IsPending = chkIsPending.Checked; } pageSettings.LastModifiedUtc = DateTime.UtcNow; if (currentUser != null) { pageSettings.LastModBy = currentUser.UserGuid; } pageSettings.LastModFromIp = SiteUtils.GetIP4Address(); bool saved = pageSettings.Save(); pageId = pageSettings.PageId; //if page was renamed url will change, if url changes we need to redirect from the old url to the new with 301 // don't create a redirect for external urls, ie starting with "http" if ( (oldUrl.Length > 0) && (newUrl.Length > 0) && (!SiteUtils.UrlsMatch(oldUrl, newUrl)) &&(!oldUrl.StartsWith("http")) &&(!newUrl.StartsWith("http")) ) { //worry about the risk of a redirect loop if the page is restored to the old url again // don't create it if a redirect for the new url exists if ( (!RedirectInfo.Exists(siteSettings.SiteId, oldUrl)) && (!RedirectInfo.Exists(siteSettings.SiteId, newUrl)) ) { RedirectInfo redirect = new RedirectInfo(); redirect.SiteGuid = siteSettings.SiteGuid; redirect.SiteId = siteSettings.SiteId; redirect.OldUrl = oldUrl; redirect.NewUrl = newUrl; redirect.Save(); } // since we have created a redirect we don't need the old friendly url FriendlyUrl oldFriendlyUrl = new FriendlyUrl(siteSettings.SiteId, oldUrl); if ((oldFriendlyUrl.FoundFriendlyUrl) && (oldFriendlyUrl.PageGuid == pageSettings.PageGuid)) { FriendlyUrl.DeleteUrl(oldFriendlyUrl.UrlId); } // url changed so it needs ot be re-indexed reIndexPage = true; clearIndex = true; } if ( ((txtUrl.Text.EndsWith(".aspx"))||siteSettings.DefaultFriendlyUrlPattern == SiteSettings.FriendlyUrlPattern.PageName) && (txtUrl.Text.StartsWith("~/")) ) { if (!friendlyUrl.FoundFriendlyUrl) { if (!WebPageInfo.IsPhysicalWebPage("~/" + friendlyUrlString)) { FriendlyUrl newFriendlyUrl = new FriendlyUrl(); newFriendlyUrl.SiteId = siteSettings.SiteId; newFriendlyUrl.SiteGuid = siteSettings.SiteGuid; newFriendlyUrl.PageGuid = pageSettings.PageGuid; newFriendlyUrl.Url = friendlyUrlString; newFriendlyUrl.RealUrl = "~/Default.aspx?pageid=" + pageId.ToInvariantString(); newFriendlyUrl.Save(); } } } // commented out 2011-08-04 can't see why would clear the sitesettings cache here //CacheHelper.ClearSiteSettingsCache(); CacheHelper.ResetSiteMapCache(); if (saved && reIndexPage) { pageSettings.PageIndex = CurrentPage.PageIndex; mojoPortal.SearchIndex.IndexHelper.RebuildPageIndexAsync(pageSettings); SiteUtils.QueueIndexing(); } else if (saved && clearIndex) { mojoPortal.SearchIndex.IndexHelper.ClearPageIndexAsync(pageSettings); } return result; }