コード例 #1
0
ファイル: mojoSetup.cs プロジェクト: joedavis01/mojoportal
        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);
            }
        }
コード例 #2
0
        private void Save()
        {
            if (store == null) { return; }

            Product product;
            if (productGuid != Guid.Empty)
            {
                product = new Product(productGuid);
            }
            else
            {
                product = new Product();
                product.StoreGuid = store.Guid;
                if (siteUser != null)
                {
                    product.CreatedBy = siteUser.UserGuid;
                    product.Created = DateTime.UtcNow;
                }
            }

            product.ContentChanged += new ContentChangedEventHandler(product_ContentChanged);

            if (ddTaxClassGuid.SelectedIndex > -1)
            {
                Guid taxClassGuid = new Guid(ddTaxClassGuid.SelectedValue);
                product.TaxClassGuid = taxClassGuid;
            }

            product.Name = txtName.Text;
            product.Teaser = edAbstract.Text;
            product.Description = edDescription.Text;
            product.MetaDescription = txtMetaDescription.Text;
            product.MetaKeywords = txtMetaKeywords.Text;

            //product.Sku = txtSku.Text; //TODO: Changed in db so sku don't need to be unique, maybe change back later (IX_ws_Product)
            product.ModelNumber = txtModelNumber.Text;
            product.Status = Product.ProductStatusFromString(ddStatus.SelectedValue);

            product.FulfillmentType
                = Product.FulfillmentTypeFromString(ddFullfillmentType.SelectedValue);

            decimal weight;
            if (!decimal.TryParse(
                txtWeight.Text,
                NumberStyles.Any,
                CultureInfo.InvariantCulture,
                out weight))
            {
                weight = 0;
            }
            product.Weight = weight;

            decimal shippingAmount;
            if (!decimal.TryParse(
                txtShippingAmount.Text,
                NumberStyles.Any,
                CultureInfo.InvariantCulture,
                out shippingAmount))
            {
                shippingAmount = 0;
            }
            product.ShippingAmount = shippingAmount;

            int qty;
            if (!int.TryParse(txtQuantityOnHand.Text,
                NumberStyles.Any,
                CultureInfo.InvariantCulture,
                out qty))
            {
                qty = 1;
            }
            product.QuantityOnHand = qty;
            product.ShowInProductList = chkShowInProductList.Checked;
            product.EnableRating = chkEnableRating.Checked;

            product.TeaserFileLink = txtTeaserFileLinkText.Text;

            if (int.TryParse(txtSortRank1.Text, NumberStyles.Number, CultureInfo.InvariantCulture, out intSortRank1))
            {
                product.SortRank1 = intSortRank1;
            }
            if (int.TryParse(txtSortRank2.Text, NumberStyles.Number, CultureInfo.InvariantCulture, out intSortRank2))
            {
                product.SortRank2 = intSortRank2;
            }

            product.LastModified = DateTime.UtcNow;
            if (siteUser != null)
            {
                product.LastModifedBy = siteUser.UserGuid;
            }

            bool needToCreateFriendlyUrl = false;

            if ((product.Url.Length == 0) && (txtName.Text.Length > 0))
            {
                product.Url = "/"
                    + SiteUtils.SuggestFriendlyUrl(
                    txtName.Text + WebStoreResources.ProductUrlSuffix,
                    siteSettings);

                needToCreateFriendlyUrl = true;

            }
            else
            {

                //TODO: change url if title changed?

            }

            if (product.Save())
            {
                productGuid = product.Guid;

                if (needToCreateFriendlyUrl)
                {

                    FriendlyUrl newUrl = new FriendlyUrl();
                    newUrl.SiteId = siteSettings.SiteId;
                    newUrl.SiteGuid = siteSettings.SiteGuid;
                    newUrl.PageGuid = product.Guid;
                    newUrl.Url = product.Url.Replace("/", string.Empty);
                    newUrl.RealUrl = "~/WebStore/ProductDetail.aspx?pageid="
                        + pageId.ToInvariantString()
                        + "&mid=" + moduleId.ToInvariantString()
                        + "&product=" + product.Guid.ToString();

                    newUrl.Save();

                }

            }
            SiteUtils.QueueIndexing();
            WebUtils.SetupRedirect(this, GetRefreshUrl());
        }
コード例 #3
0
        private void dlUrlMap_ItemCommand(object sender, DataListCommandEventArgs e)
        {
            int urlID = Convert.ToInt32(dlUrlMap.DataKeys[e.Item.ItemIndex]);
            FriendlyUrl friendlyUrl = new FriendlyUrl(urlID);

            switch (e.CommandName)
            {
                case "edit":
                    dlUrlMap.EditItemIndex = e.Item.ItemIndex;
                    Control c = e.Item.FindControl("ddPagesEdit");
                    DropDownList dd = null;
                    if ((c != null) && (pageList != null))
                    {
                        dd = (DropDownList)c;
                        dd.DataSource = pageList;
                        dd.DataBind();

                    }
                    PopulateControls();
                    if (dd != null)
                    {
                        String selection = ParsePageId(friendlyUrl.RealUrl);
                        if (selection.Length > 0)
                        {
                            ListItem listItem = dd.Items.FindByValue(selection);
                            if (listItem != null)
                            {
                                dd.ClearSelection();
                                listItem.Selected = true;
                            }
                        }
                    }
                    break;

                case "apply":

                    TextBox txtItemFriendlyUrl
                        = (TextBox)e.Item.FindControl("txtItemFriendlyUrl");

                    if (txtItemFriendlyUrl.Text.Length > 0)
                    {
                        Control cEdit = e.Item.FindControl("ddPagesEdit");
                        if (cEdit != null)
                        {
                            DropDownList ddEdit = (DropDownList)cEdit;
                            friendlyUrl.Url = txtItemFriendlyUrl.Text;
                            if (WebPageInfo.IsPhysicalWebPage("~/" + friendlyUrl.Url))
                            {
                                this.lblError.Text = Resource.FriendlyUrlWouldMaskPhysicalPageWarning;
                                return;
                            }

                            int pageId = -1;
                            if (int.TryParse(ddEdit.SelectedValue, out pageId))
                            {
                                if (pageId > -1)
                                {
                                    PageSettings page = new PageSettings(siteSettings.SiteId, pageId);
                                    friendlyUrl.PageGuid = page.PageGuid;
                                }

                            }

                            friendlyUrl.RealUrl = "Default.aspx?pageid=" + ddEdit.SelectedValue;
                            friendlyUrl.Save();

                        }

                        WebUtils.SetupRedirect(this, Request.RawUrl);
                    }
                    else
                    {
                        this.lblError.Text = Resource.FriendlyUrlInvalidFriendlyUrlMessage;

                    }
                    break;

                case "applymanual":

                    if (
                        (
                            (((TextBox)e.Item.FindControl("txtItemFriendlyUrl")).Text.Length > 0)
                        )
                        && (
                            (((TextBox)e.Item.FindControl("txtItemRealUrl")).Text.Length > 0)
                            )
                      )
                    {
                        friendlyUrl.Url = ((TextBox)e.Item.FindControl("txtItemFriendlyUrl")).Text;
                        if (WebPageInfo.IsPhysicalWebPage("~/" + friendlyUrl.Url))
                        {
                            this.lblError.Text = Resource.FriendlyUrlWouldMaskPhysicalPageWarning;
                            return;
                        }
                        friendlyUrl.RealUrl = ((TextBox)e.Item.FindControl("txtItemRealUrl")).Text;
                        friendlyUrl.PageGuid = Guid.Empty;
                        friendlyUrl.Save();
                        WebUtils.SetupRedirect(this, Request.RawUrl);
                    }
                    else
                    {
                        this.lblError.Text = Resource.FriendlyUrlInvalidEntryMessage;
                    }
                    break;

                case "delete":

                    FriendlyUrl.DeleteUrl(urlID);
                    WebUtils.SetupRedirect(this, Request.RawUrl);
                    break;

                case "cancel":
                    WebUtils.SetupRedirect(this, Request.RawUrl);
                    break;

            }
        }
コード例 #4
0
ファイル: FeedEdit.aspx.cs プロジェクト: saiesh86/TravelBlog
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            Page.Validate("feeds");
            if (!Page.IsValid) { return; }

            RssFeed feed = new RssFeed(ModuleId, ItemId);

            if (feed.ModuleId != ModuleId)
            {
                SiteUtils.RedirectToAccessDeniedPage(this);
                return;
            }

            feed.ModuleId = ModuleId;
            feed.Author = txtAuthor.Text;
            feed.Url = txtWebSite.Text;
            feed.RssUrl = txtRssUrl.Text;
            feed.ImageUrl = txtImageUrl.Text;
            int sortRank = 500;
            int.TryParse(txtSortRank.Text, out sortRank);
            feed.SortRank = sortRank;

            SiteUser siteUser = SiteUtils.GetCurrentSiteUser();
            if (siteUser == null) return;

            Module module = new Module(ModuleId);
            feed.ModuleGuid = module.ModuleGuid;
            feed.UserId = siteUser.UserId;
            feed.UserGuid = siteUser.UserGuid;
            feed.LastModUserGuid = siteUser.UserGuid;
            feed.PublishByDefault = chkPublishByDefault.Checked;

            if (feed.Save())
            {
                CurrentPage.UpdateLastModifiedTime();

                FeedCache.RefreshFeed(
                    feed,
                    ModuleId,
                    module.ModuleGuid,
                    config.MaxDaysOld,
                    config.MaxEntriesPerFeed,
                    config.EnableSelectivePublishing);

                String rssFriendlyUrl = "aggregator" + ModuleId.ToInvariantString() + "rss.aspx";
                if (!FriendlyUrl.Exists(siteSettings.SiteId, rssFriendlyUrl))
                {
                    FriendlyUrl friendlyUrl = new FriendlyUrl();
                    friendlyUrl.SiteId = siteSettings.SiteId;
                    friendlyUrl.SiteGuid = siteSettings.SiteGuid;
                    friendlyUrl.Url = rssFriendlyUrl;
                    friendlyUrl.RealUrl = "~/FeedManager/FeedAggregate.aspx?pageid=" + PageId.ToInvariantString() + "&mid=" + ModuleId.ToInvariantString();
                    friendlyUrl.Save();
                }

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

                WebUtils.SetupRedirect(this, SiteUtils.GetCurrentPageUrl());
            }
        }
コード例 #5
0
        void btnAddExpert_Click(object sender, EventArgs e)
        {
            if (
                (this.txtFriendlyUrl.Text.Length > 0)
                && (this.txtRealUrl.Text.Length > 0)
                )
            {

                if (WebPageInfo.IsPhysicalWebPage("~/" + txtFriendlyUrl.Text))
                {
                    this.lblError.Text = Resource.FriendlyUrlWouldMaskPhysicalPageWarning;
                    return;
                }

                if (FriendlyUrl.Exists(siteSettings.SiteId, txtFriendlyUrl.Text))
                {
                    this.lblError.Text = Resource.FriendlyUrlDuplicateWarning;
                    return;
                }

                FriendlyUrl url = new FriendlyUrl();
                url.SiteId = siteSettings.SiteId;
                url.SiteGuid = siteSettings.SiteGuid;
                url.Url = this.txtFriendlyUrl.Text;
                url.RealUrl = this.txtRealUrl.Text;
                url.Save();

                WebUtils.SetupRedirect(this, Request.RawUrl);
            }
            else
            {
                this.lblError.Text = Resource.FriendlyUrlInvalidEntryMessage;
            }
        }
コード例 #6
0
        private void btnAddFriendlyUrl_Click(object sender, EventArgs e)
        {
            if (this.txtFriendlyUrl.Text.Length > 0)
            {
                if (WebPageInfo.IsPhysicalWebPage("~/" + txtFriendlyUrl.Text))
                {
                    this.lblError.Text = Resource.FriendlyUrlWouldMaskPhysicalPageWarning;
                    return;
                }

                if (FriendlyUrl.Exists(siteSettings.SiteId, txtFriendlyUrl.Text))
                {
                    this.lblError.Text = Resource.FriendlyUrlDuplicateWarning;
                    return;
                }

                if (FriendlyUrl.Exists(siteSettings.SiteId, txtFriendlyUrl.Text.ToLower()))
                {
                    this.lblError.Text = Resource.FriendlyUrlDuplicateWarning;
                    return;
                }

                FriendlyUrl url = new FriendlyUrl();
                url.SiteId = siteSettings.SiteId;
                url.SiteGuid = siteSettings.SiteGuid;

                int pageId = -1;
                if (int.TryParse(ddPages.SelectedValue, out pageId))
                {
                    if (pageId > -1)
                    {
                        PageSettings page = new PageSettings(siteSettings.SiteId, pageId);
                        url.PageGuid = page.PageGuid;
                    }

                }

                url.Url = this.txtFriendlyUrl.Text;
                url.RealUrl = "Default.aspx?pageid=" + ddPages.SelectedValue;
                url.Save();

                WebUtils.SetupRedirect(this, Request.RawUrl);
            }
            else
            {
                this.lblError.Text = Resource.FriendlyUrlInvalidFriendlyUrlMessage;
            }
        }
コード例 #7
0
        private void Save()
        {
            if (store == null) { return; }

            Offer offer;
            if (offerGuid != Guid.Empty)
            {
                offer = new Offer(offerGuid);
            }
            else
            {
                offer = new Offer();
                offer.Created = DateTime.UtcNow;
                offer.CreatedBy = siteUser.UserGuid;
                offer.CreatedFromIP = SiteUtils.GetIP4Address();
            }

            if (config.IndexOffersInSearch)
            {
                offer.ContentChanged += new ContentChangedEventHandler(offer_ContentChanged);
            }

            offer.Name = txtName.Text;
            offer.ProductListName = txtProductListName.Text;
            offer.Teaser = edAbstract.Text;
            offer.Description = edDescription.Text;
            offer.StoreGuid = store.Guid;
            offer.IsVisible = chkIsVisible.Checked;
            offer.IsSpecial = chkIsSpecial.Checked;
            offer.IsDonation = chkIsDonation.Checked;
            offer.ShowDetailLink = chkShowDetailLink.Checked;
            offer.MetaDescription = txtMetaDescription.Text;
            offer.MetaKeywords = txtMetaKeywords.Text;

            // If the sort rank inputs are left null on the product
            //		and offer creation screens, the in.Parse gets all
            //		bent out of shape so I converted to TryParse
            if (int.TryParse(txtSortRank1.Text, NumberStyles.Number, CultureInfo.InvariantCulture, out intSortRank1))
            {
                offer.SortRank1 = intSortRank1;
            }
            if (int.TryParse(txtSortRank2.Text, NumberStyles.Number, CultureInfo.InvariantCulture, out intSortRank2))
            {
                offer.SortRank2 = intSortRank2;
            }

            offer.Price = decimal.Parse(txtPrice.Text, NumberStyles.Currency, currencyCulture);

            if (!String.IsNullOrEmpty(ddTaxClassGuid.SelectedValue))
            {
                Guid taxClassGuid = new Guid(ddTaxClassGuid.SelectedValue);
                offer.TaxClassGuid = taxClassGuid;
            }

            offer.LastModified = DateTime.UtcNow;
            offer.LastModifiedBy = siteUser.UserGuid;
            offer.LastModifiedFromIP = SiteUtils.GetIP4Address();

            bool needToCreateFriendlyUrl = false;

            if ((offer.Url.Length == 0) && (txtName.Text.Length > 0))
            {
                offer.Url = "/"
                    + SiteUtils.SuggestFriendlyUrl(
                    txtName.Text + WebStoreResources.OfferUrlSuffix,
                    siteSettings);

                needToCreateFriendlyUrl = true;

            }
            else
            {

                //TODO: change url if title changed?

            }

            if (offer.Save())
            {
                offerGuid = offer.Guid;

                if (needToCreateFriendlyUrl)
                {

                    FriendlyUrl newUrl = new FriendlyUrl();
                    newUrl.SiteId = siteSettings.SiteId;
                    newUrl.SiteGuid = siteSettings.SiteGuid;
                    newUrl.PageGuid = offer.Guid;
                    newUrl.Url = offer.Url.Replace("/", string.Empty);
                    newUrl.RealUrl = "~/WebStore/OfferDetail.aspx?pageid="
                        + pageId.ToInvariantString()
                        + "&mid=" + moduleId.ToInvariantString()
                        + "&offer=" + offer.Guid.ToString();

                    newUrl.Save();

                }

            }
            SiteUtils.QueueIndexing();
            WebUtils.SetupRedirect(this, GetRefreshUrl());
        }
コード例 #8
0
ファイル: EditPost.aspx.cs プロジェクト: saiesh86/TravelBlog
        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();
        }
コード例 #9
0
        public void InstallContent(Module module, string configInfo)
        {
            if (string.IsNullOrEmpty(configInfo)) { return; }

            Store store = new Store(module.SiteGuid, module.ModuleId);
            if (store.Guid == Guid.Empty) // No store created yet
            {
                store = new Store();
                store.SiteGuid = module.SiteGuid;
                store.ModuleId = module.ModuleId;
                store.Save();
            }

            SiteSettings siteSettings = new SiteSettings(module.SiteId);

            Guid taxClassGuid = Guid.Empty;

            List<TaxClass> taxClasses = TaxClass.GetList(siteSettings.SiteGuid);
            if (taxClasses.Count == 0)
            {
                TaxClass taxClass = new TaxClass();
                taxClass.SiteGuid = siteSettings.SiteGuid;
                taxClass.Title = "Taxable";
                taxClass.Description = "Taxable";
                taxClass.Save();

                taxClass = new TaxClass();
                taxClass.SiteGuid = siteSettings.SiteGuid;
                taxClass.Title = "Not Taxable";
                taxClass.Description = "Not Taxable";
                taxClass.Save();

                taxClassGuid = taxClass.Guid;

            }
            else
            {
                foreach (TaxClass t in taxClasses)
                {
                    if (t.Title == "Not Taxable")
                    {
                        taxClassGuid = t.Guid;
                    }
                }
            }

            SiteUser admin = SiteUser.GetNewestUser(siteSettings);

            XmlDocument xml = new XmlDocument();

            using (StreamReader stream = File.OpenText(HostingEnvironment.MapPath(configInfo)))
            {
                xml.LoadXml(stream.ReadToEnd());
            }

            CultureInfo currencyCulture = new CultureInfo("en-US");

            if (xml.DocumentElement.Name == "store")
            {
                // update the store
                XmlAttributeCollection storeAttrributes = xml.DocumentElement.Attributes;

                if (storeAttrributes["storeName"] != null)
                {
                    store.Name = storeAttrributes["storeName"].Value;
                }

                if (storeAttrributes["emailFrom"] != null)
                {
                    store.EmailFrom = storeAttrributes["emailFrom"].Value;
                }

                if (storeAttrributes["currencyCulture"] != null)
                {
                    currencyCulture = new CultureInfo(storeAttrributes["currencyCulture"].Value);
                }

                if (storeAttrributes["ownerName"] != null)
                {
                    store.OwnerName = storeAttrributes["ownerName"].Value;
                }

                if (storeAttrributes["ownerEmail"] != null)
                {
                    store.OwnerEmail = storeAttrributes["ownerEmail"].Value;
                }

                if (storeAttrributes["city"] != null)
                {
                    store.City = storeAttrributes["city"].Value;
                }

                if (storeAttrributes["postalCode"] != null)
                {
                    store.PostalCode = storeAttrributes["postalCode"].Value;
                }

                if (storeAttrributes["phone"] != null)
                {
                    store.Phone = storeAttrributes["phone"].Value;
                }

                if (storeAttrributes["address"] != null)
                {
                    store.Address = storeAttrributes["address"].Value;
                }

                if (storeAttrributes["countryGuid"] != null)
                {
                    string g = storeAttrributes["countryGuid"].Value;
                    if(g.Length == 36)
                    {
                        Guid countryGuid = new Guid(g);
                        store.CountryGuid = countryGuid;
                    }
                }

                if (storeAttrributes["stateGuid"] != null)
                {
                    string s = storeAttrributes["stateGuid"].Value;
                    if(s.Length == 36)
                    {
                        Guid stateGuid = new Guid(s);
                        store.ZoneGuid = stateGuid;
                    }
                }

                foreach (XmlNode descriptionNode in xml.DocumentElement.ChildNodes)
                {
                    if (descriptionNode.Name == "storeDescription")
                    {
                        store.Description = descriptionNode.InnerText;
                        break;
                    }
                }

                store.Save();

                //module settings
                foreach (XmlNode node in xml.DocumentElement.ChildNodes)
                {
                    if (node.Name == "moduleSetting")
                    {
                        XmlAttributeCollection settingAttributes = node.Attributes;

                        if ((settingAttributes["settingKey"] != null) && (settingAttributes["settingKey"].Value.Length > 0))
                        {
                            string key = settingAttributes["settingKey"].Value;
                            string val = string.Empty;
                            if (settingAttributes["settingValue"] != null)
                            {
                                val = settingAttributes["settingValue"].Value;
                            }

                            ModuleSettings.UpdateModuleSetting(module.ModuleGuid, module.ModuleId, key, val);
                        }
                    }
                }

                if (storeAttrributes["productFilesPath"] != null)
                {
                    if (storeAttrributes["productFilesPath"].Value.Length > 0)
                    {
                        string destPath = "~/Data/Sites/" + module.SiteId.ToInvariantString() + "/webstoreproductfiles/";
                        if (!Directory.Exists(HostingEnvironment.MapPath(destPath)))
                        {
                            Directory.CreateDirectory(HostingEnvironment.MapPath(destPath));
                        }

                        IOHelper.CopyFolderContents(HostingEnvironment.MapPath(storeAttrributes["productFilesPath"].Value), HostingEnvironment.MapPath(destPath));
                    }

                }

                if (storeAttrributes["teaserFilesPath"] != null)
                {
                    if (storeAttrributes["teaserFilesPath"].Value.Length > 0)
                    {
                        string destPath = "~/Data/Sites/" + module.SiteId.ToInvariantString() + "/webstoreproductpreviewfiles/";
                        if (!Directory.Exists(HostingEnvironment.MapPath(destPath)))
                        {
                            Directory.CreateDirectory(HostingEnvironment.MapPath(destPath));
                        }

                        IOHelper.CopyFolderContents(HostingEnvironment.MapPath(storeAttrributes["teaserFilesPath"].Value), HostingEnvironment.MapPath(destPath));
                    }

                }

                FullfillDownloadTerms term = new FullfillDownloadTerms();
                term.Name = WebStoreResources.DownloadUnlimited;
                term.Description = WebStoreResources.DownloadUnlimited;
                if (admin != null)
                {
                    term.CreatedBy = admin.UserGuid;
                }
                term.StoreGuid = store.Guid;
                term.Save();

                XmlNode offersNode = null;
                foreach (XmlNode n in xml.DocumentElement.ChildNodes)
                {
                    if (n.Name == "offers")
                    {
                        offersNode = n;
                        break;
                    }
                }

                if (offersNode != null)
                {
                    foreach (XmlNode node in offersNode.ChildNodes)
                    {
                        if (node.Name == "offer")
                        {
                            XmlAttributeCollection offerAttrributes = node.Attributes;

                            Offer offer = new Offer();
                            offer.StoreGuid = store.Guid;
                            offer.Created = DateTime.UtcNow;
                            offer.LastModified = DateTime.UtcNow;

                            if (admin != null)
                            {
                                offer.CreatedBy = admin.UserGuid;
                                offer.LastModifiedBy = admin.UserGuid;
                            }

                            if (offerAttrributes["offerName"] != null)
                            {
                                offer.Name = offerAttrributes["offerName"].Value;
                            }

                            if (offerAttrributes["nameOnProductList"] != null)
                            {
                                offer.ProductListName = offerAttrributes["nameOnProductList"].Value;
                            }

                            if (
                                (offerAttrributes["isVisible"] != null)
                                && (offerAttrributes["isVisible"].Value.ToLower() == "true")
                                )
                            {
                                offer.IsVisible = true;
                            }

                            if (
                                (offerAttrributes["isSpecial"] != null)
                                && (offerAttrributes["isSpecial"].Value.ToLower() == "true")
                                )
                            {
                                offer.IsSpecial = true;
                            }

                            //offer.IsDonation = chkIsDonation.Checked;

                            if (
                                (offerAttrributes["showOfferDetailLink"] != null)
                                && (offerAttrributes["showOfferDetailLink"].Value.ToLower() == "true")
                                )
                            {
                                offer.ShowDetailLink = true;
                            }

                            if (offerAttrributes["primarySort"] != null)
                            {
                                int sort = 5000;
                                if (int.TryParse(offerAttrributes["primarySort"].Value,
                                    out sort))
                                {
                                    offer.SortRank1 = sort;
                                }
                            }

                            if (offerAttrributes["secondarySort"] != null)
                            {
                                int sort = 5000;
                                if (int.TryParse(offerAttrributes["secondarySort"].Value,
                                    out sort))
                                {
                                    offer.SortRank2 = sort;
                                }
                            }

                            if (offerAttrributes["price"] != null)
                            {
                                offer.Price = decimal.Parse(offerAttrributes["price"].Value, NumberStyles.Currency, currencyCulture);
                            }

                            offer.TaxClassGuid = taxClassGuid;

                            offer.Url = "/"
                                    + SiteUtils.SuggestFriendlyUrl(
                                    offer.Name + WebStoreResources.OfferUrlSuffix,
                                    siteSettings);

                            foreach (XmlNode descriptionNode in node.ChildNodes)
                            {
                                if (descriptionNode.Name == "abstract")
                                {
                                    offer.Teaser = descriptionNode.InnerText;
                                    break;
                                }
                            }

                            foreach (XmlNode descriptionNode in node.ChildNodes)
                            {
                                if (descriptionNode.Name == "description")
                                {
                                    offer.Description = descriptionNode.InnerText;
                                    break;
                                }
                            }

                            if (offer.Save())
                            {

                                FriendlyUrl newUrl = new FriendlyUrl();
                                newUrl.SiteId = siteSettings.SiteId;
                                newUrl.SiteGuid = siteSettings.SiteGuid;
                                newUrl.PageGuid = offer.Guid;
                                newUrl.Url = offer.Url.Replace("/", string.Empty);
                                newUrl.RealUrl = "~/WebStore/OfferDetail.aspx?pageid="
                                    + module.PageId.ToInvariantString()
                                    + "&mid=" + module.ModuleId.ToInvariantString()
                                    + "&offer=" + offer.Guid.ToString();

                                newUrl.Save();

                            }

                            foreach (XmlNode productNode in node.ChildNodes)
                            {
                                if (productNode.Name == "product")
                                {
                                    XmlAttributeCollection productAttrributes = productNode.Attributes;

                                    Product product = new Product();
                                    product.StoreGuid = store.Guid;
                                    if (admin != null)
                                    {
                                        product.CreatedBy = admin.UserGuid;

                                    }

                                    product.Created = DateTime.UtcNow;
                                    product.TaxClassGuid = taxClassGuid;

                                    if (productAttrributes["name"] != null)
                                    {
                                        product.Name = productAttrributes["name"].Value;
                                    }

                                    if (productAttrributes["modelNumber"] != null)
                                    {
                                        product.ModelNumber = productAttrributes["modelNumber"].Value;
                                    }

                                    if (productAttrributes["teaser"] != null)
                                    {
                                        product.TeaserFile = productAttrributes["teaser"].Value;
                                    }

                                    if (productAttrributes["fulfillmentType"] != null)
                                    {
                                        product.FulfillmentType
                                        = Product.FulfillmentTypeFromString(productAttrributes["fulfillmentType"].Value);
                                    }

                                    product.Status = ProductStatus.Available;
                                    product.Weight = 0;
                                    product.QuantityOnHand = 0;

                                    if (
                                        (productAttrributes["showInProductList"] != null)
                                        && (productAttrributes["showInProductList"].Value.ToLower() == "true")
                                        )
                                    {
                                        product.ShowInProductList = true;
                                    }

                                    if (
                                        (productAttrributes["enableRating"] != null)
                                        && (productAttrributes["enableRating"].Value.ToLower() == "true")
                                        )
                                    {
                                        product.EnableRating = true;
                                    }

                                    if (productAttrributes["primarySort"] != null)
                                    {
                                        int sort = 5000;
                                        if (int.TryParse(productAttrributes["primarySort"].Value,
                                            out sort))
                                        {
                                            product.SortRank1 = sort;
                                        }
                                    }

                                    if (productAttrributes["secondarySort"] != null)
                                    {
                                        int sort = 5000;
                                        if (int.TryParse(productAttrributes["secondarySort"].Value,
                                            out sort))
                                        {
                                            product.SortRank2 = sort;
                                        }
                                    }

                                    product.Url = "/"
                                            + SiteUtils.SuggestFriendlyUrl(
                                            product.Name + WebStoreResources.ProductUrlSuffix,
                                            siteSettings);

                                    foreach (XmlNode descriptionNode in productNode.ChildNodes)
                                    {
                                        if (descriptionNode.Name == "abstract")
                                        {
                                            product.Teaser = descriptionNode.InnerText;
                                            break;
                                        }
                                    }

                                    foreach (XmlNode descriptionNode in productNode.ChildNodes)
                                    {
                                        if (descriptionNode.Name == "description")
                                        {
                                            product.Description = descriptionNode.InnerText;
                                            break;
                                        }
                                    }

                                    if (product.Save())
                                    {
                                        if (productAttrributes["file"] != null)
                                        {

                                            ProductFile productFile = new ProductFile(product.Guid);
                                            productFile.ServerFileName = productAttrributes["file"].Value;

                                            if (productAttrributes["fileName"] != null)
                                            {
                                                productFile.FileName = productAttrributes["fileName"].Value;
                                            }

                                            if (admin != null)
                                            {
                                                productFile.CreatedBy = admin.UserGuid;
                                            }

                                            productFile.Save();
                                        }

                                        FriendlyUrl newUrl = new FriendlyUrl();
                                        newUrl.SiteId = siteSettings.SiteId;
                                        newUrl.SiteGuid = siteSettings.SiteGuid;
                                        newUrl.PageGuid = product.Guid;
                                        newUrl.Url = product.Url.Replace("/", string.Empty);
                                        newUrl.RealUrl = "~/WebStore/ProductDetail.aspx?pageid="
                                            + module.PageId.ToInvariantString()
                                            + "&mid=" + module.ModuleId.ToInvariantString()
                                            + "&product=" + product.Guid.ToString();

                                        newUrl.Save();

                                    }

                                    // create offer product
                                    OfferProduct offerProduct = new OfferProduct();
                                    if (admin != null)
                                    {
                                        offerProduct.CreatedBy = admin.UserGuid;
                                    }

                                    offerProduct.ProductGuid = product.Guid;

                                    if (productAttrributes["fulfillmentType"] != null)
                                    {
                                        offerProduct.FullfillType = Convert.ToByte(productAttrributes["fulfillmentType"].Value);
                                    }

                                    if (productAttrributes["sortOrder"] != null)
                                    {
                                        int sort = 100;
                                        if (int.TryParse(productAttrributes["sortOrder"].Value, out sort))
                                        {
                                           offerProduct.SortOrder = sort;
                                        }
                                    }

                                    if (productAttrributes["quantity"] != null)
                                    {
                                        int qty = 1;
                                        if (int.TryParse(productAttrributes["quantity"].Value, out qty))
                                        {
                                            offerProduct.Quantity = qty;
                                        }
                                    }

                                    offerProduct.FullfillType = (byte)product.FulfillmentType;
                                    offerProduct.FullFillTermsGuid = term.Guid;

                                    offerProduct.OfferGuid = offer.Guid;
                                    offerProduct.Save();

                                }
                            }

                        }

                    }

                }

            }

            //create product
        }
コード例 #10
0
        /// <summary>
        /// metaWeblog.newPost method
        /// </summary>
        /// <param name="blogId">
        /// always 1000 in BlogEngine since it is a singlar blog instance
        /// </param>
        /// <param name="userName">
        /// login username
        /// </param>
        /// <param name="password">
        /// login password
        /// </param>
        /// <param name="sentPost">
        /// struct with post details
        /// </param>
        /// <param name="publish">
        /// mark as published?
        /// </param>
        /// <returns>
        /// postID as string
        /// </returns>
        internal string NewPost(string blogId, string userName, string password, MWAPost sentPost, bool publish)
        {
            int moduleId = Convert.ToInt32(blogId);

            if (!UserCanPostToBlog(userName, moduleId))
            {
                throw new MetaWeblogException("11", MetaweblogResources.AccessDenied);
            }

            try
            {
                Module module = new Module(moduleId);

                Blog post = new Blog();
                post.ModuleId = module.ModuleId;
                post.ModuleGuid = module.ModuleGuid;

                post.UserGuid = siteUser.UserGuid;
                post.LastModUserGuid = siteUser.UserGuid;

                if ((sentPost.postDate != null) && (sentPost.postDate > DateTime.MinValue) && (sentPost.postDate < DateTime.MaxValue))
                {
                    if (!WebConfigSettings.DisableUseOfPassedInDateForMetaWeblogApi) { post.StartDate = sentPost.postDate; }
                }

                post.Title = sentPost.title;
                post.Description = SiteUtils.ChangeFullyQualifiedLocalUrlsToRelative(navigationSiteRoot, imageSiteRoot, sentPost.description);

                if (!string.IsNullOrEmpty(sentPost.excerpt))
                {
                    if (BlogConfiguration.UseExcerptFromMetawblogAsMetaDescription)
                    {
                        post.MetaDescription = UIHelper.CreateExcerpt(sentPost.excerpt, BlogConfiguration.MetaDescriptionMaxLengthToGenerate);
                    }
                    post.Excerpt = SiteUtils.ChangeFullyQualifiedLocalUrlsToRelative(navigationSiteRoot, imageSiteRoot, sentPost.excerpt);
                }
                post.IncludeInFeed = true;
                post.IsPublished = publish;

                //post.Slug = sentPost.slug;
                //string author = String.IsNullOrEmpty(sentPost.author) ? userName : sentPost.author;

                switch (sentPost.commentPolicy)
                {
                    //closed
                    case "2":
                        post.AllowCommentsForDays = -1; // closed
                        break;

                    // open
                    case "1":
                    default:

                        Hashtable moduleSettings = ModuleSettings.GetModuleSettings(post.ModuleId);
                        BlogConfiguration config = new BlogConfiguration(moduleSettings);
                        post.AllowCommentsForDays = config.DefaultCommentDaysAllowed;

                        break;

                }

                string newUrl = SiteUtils.SuggestFriendlyUrl(post.Title, siteSettings);

                post.ItemUrl = "~/" + newUrl;

                if (!post.Title.Contains("Theme Detection")) // don't index a temp post from livewriter that will be deleted
                {
                    post.ContentChanged += new ContentChangedEventHandler(blog_ContentChanged);
                }

                post.Save();

                int pageId = GetPageIdForModule(moduleId);

                FriendlyUrl newFriendlyUrl = new FriendlyUrl();
                newFriendlyUrl.SiteId = siteSettings.SiteId;
                newFriendlyUrl.SiteGuid = siteSettings.SiteGuid;
                newFriendlyUrl.PageGuid = post.BlogGuid;
                newFriendlyUrl.Url = newUrl;
                newFriendlyUrl.RealUrl = "~/Blog/ViewPost.aspx?pageid="
                    + pageId.ToInvariantString()
                    + "&mid=" + post.ModuleId.ToInvariantString()
                    + "&ItemID=" + post.ItemId.ToInvariantString();

                if (pageId > -1)
                {
                    newFriendlyUrl.Save();
                }

                SetCategories(post, sentPost);

                //post.Tags.Clear();
                //foreach (var item in sentPost.tags.Where(item => item != null && item.Trim() != string.Empty))
                //{
                //    post.Tags.Add(item);
                //}

                if (!post.Title.Contains("Theme Detection")) // don't index a temp post from livewriter that will be deleted
                {
                    SiteUtils.QueueIndexing();
                }

                return post.ItemId.ToString();

            }
            catch (Exception ex)
            {
                log.Error(ex);
                throw new MetaWeblogException("12", string.Format("Create new post failed.  Error: {0}", ex.Message));
            }
        }
コード例 #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();
        }
コード例 #12
0
        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;
        }
コード例 #13
0
        public void InstallContent(Module module, string configInfo)
        {
            if (string.IsNullOrEmpty(configInfo)) { return; }

            SiteSettings siteSettings = new SiteSettings(module.SiteId);
            SiteUser admin = SiteUser.GetNewestUser(siteSettings);

            XmlDocument xml = new XmlDocument();

            using (StreamReader stream = File.OpenText(HostingEnvironment.MapPath(configInfo)))
            {
                xml.LoadXml(stream.ReadToEnd());
            }

            XmlNode postsNode = null;
            foreach (XmlNode n in xml.DocumentElement.ChildNodes)
            {
                if (n.Name == "posts")
                {
                    postsNode = n;
                    break;
                }
            }

            if (postsNode != null)
            {
                foreach (XmlNode node in postsNode.ChildNodes)
                {
                    if (node.Name == "post")
                    {
                        XmlAttributeCollection postAttrributes = node.Attributes;

                        Blog b = new Blog();
                        b.ModuleGuid = module.ModuleGuid;
                        b.ModuleId = module.ModuleId;

                        if ((postAttrributes["title"] != null) && (postAttrributes["title"].Value.Length > 0))
                        {
                            b.Title = postAttrributes["title"].Value;
                        }

                        b.ItemUrl = "~/" + SiteUtils.SuggestFriendlyUrl(b.Title, siteSettings);

                        foreach (XmlNode descriptionNode in node.ChildNodes)
                        {
                            if (descriptionNode.Name == "excerpt")
                            {
                                b.Excerpt = descriptionNode.InnerText;
                                break;
                            }
                        }

                        foreach (XmlNode descriptionNode in node.ChildNodes)
                        {
                            if (descriptionNode.Name == "description")
                            {
                                b.Description = descriptionNode.InnerText;
                                break;
                            }
                        }

                        b.UserGuid = admin.UserGuid;

                        if (b.Save())
                        {
                            FriendlyUrl newFriendlyUrl = new FriendlyUrl();
                            newFriendlyUrl.SiteId = siteSettings.SiteId;
                            newFriendlyUrl.SiteGuid = siteSettings.SiteGuid;
                            newFriendlyUrl.PageGuid = b.BlogGuid;
                            newFriendlyUrl.Url = b.ItemUrl.Replace("~/", string.Empty); ;
                            newFriendlyUrl.RealUrl = "~/Blog/ViewPost.aspx?pageid="
                                + module.PageId.ToInvariantString()
                                + "&mid=" + b.ModuleId.ToInvariantString()
                                + "&ItemID=" + b.ItemId.ToInvariantString();

                            newFriendlyUrl.Save();

                        }

                    }
                }
            }

            foreach (XmlNode node in xml.DocumentElement.ChildNodes)
            {
                if (node.Name == "moduleSetting")
                {
                    XmlAttributeCollection settingAttributes = node.Attributes;

                    if ((settingAttributes["settingKey"] != null) && (settingAttributes["settingKey"].Value.Length > 0))
                    {
                        string key = settingAttributes["settingKey"].Value;
                        string val = string.Empty;
                        if (settingAttributes["settingValue"] != null)
                        {
                            val = settingAttributes["settingValue"].Value;
                        }

                        ModuleSettings.UpdateModuleSetting(module.ModuleGuid, module.ModuleId, key, val);
                    }
                }
            }
        }