示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PageRelativePathContextRegion"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        public PageRelativePathContextRegion(HttpContextBase context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            this.context      = context;
            this.originalPath = context.Request.AppRelativeCurrentExecutionFilePath;
            var originalWithSlash = VirtualPathUtility.AppendTrailingSlash(this.originalPath);

            bool?isFrontendPageEdit = context.Items["IsFrontendPageEdit"] as bool?;
            var  currentNode        = SiteMapBase.GetCurrentNode();

            if (currentNode != null && !(isFrontendPageEdit.HasValue && isFrontendPageEdit.Value))
            {
                var nodeUrl = currentNode.Url.StartsWith("~/", StringComparison.Ordinal) ? RouteHelper.ResolveUrl(currentNode.Url, UrlResolveOptions.ApplicationRelative | UrlResolveOptions.AppendTrailingSlash) : currentNode.Url;
                if (originalWithSlash.StartsWith(nodeUrl, StringComparison.OrdinalIgnoreCase))
                {
                    var newPath = originalWithSlash.Right(originalWithSlash.Length - nodeUrl.Length);

                    this.context.RewritePath("~/" + newPath);
                }
                else if (currentNode.IsHomePage() &&
                         RouteHelper.ResolveUrl(SystemManager.CurrentContext.CurrentSite.GetUri().AbsolutePath, UrlResolveOptions.ApplicationRelative | UrlResolveOptions.AppendTrailingSlash) == originalWithSlash)
                {
                    // The request is to the root of the site
                    this.context.RewritePath("~/");
                }
            }
            else
            {
                this.context.RewritePath("~/");
            }
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PageRelativePathContextRegion"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        public PageRelativePathContextRegion(HttpContextBase context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            this.context      = context;
            this.originalPath = context.Request.AppRelativeCurrentExecutionFilePath;
            var originalWithSlash = VirtualPathUtility.AppendTrailingSlash(this.originalPath);

            var currentNode = SiteMapBase.GetCurrentNode();

            if (currentNode != null)
            {
                var nodeUrl = currentNode.Url.StartsWith("~/", StringComparison.Ordinal) ? RouteHelper.ResolveUrl(currentNode.Url, UrlResolveOptions.ApplicationRelative | UrlResolveOptions.AppendTrailingSlash) : currentNode.Url;
                if (originalWithSlash.StartsWith(nodeUrl, StringComparison.OrdinalIgnoreCase))
                {
                    var newPath = originalWithSlash.Right(originalWithSlash.Length - nodeUrl.Length);
                    if (newPath.Equals("Action/Edit/", StringComparison.OrdinalIgnoreCase))
                    {
                        newPath = string.Empty;
                    }

                    this.context.RewritePath("~/" + newPath);
                }
            }
            else
            {
                this.context.RewritePath("~/");
            }
        }
        /// <summary>
        /// Executes checks which need to run for every request e.g. notifyLogin if CMS is running the session and extending the session if Gigya is managing it.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="settings"></param>
        public static void ProcessRequestChecks(HttpContext context, IGigyaModuleSettings settings = null)
        {
            var currentNode = SiteMapBase.GetCurrentNode();

            if (currentNode != null && currentNode.IsBackend)
            {
                return;
            }

            // don't need to do anything if the user is editing content in the CMS
            var identity = ClaimsManager.GetCurrentIdentity();

            if (identity.IsBackendUser)
            {
                return;
            }

            if (context.Items.Contains(_executedProcessRequestKey))
            {
                return;
            }

            context.Items[_executedProcessRequestKey] = true;

            var settingsHelper   = new GigyaSettingsHelper();
            var logger           = LoggerFactory.Instance();
            var membershipHelper = new GigyaMembershipHelper(new GigyaApiHelper(settingsHelper, logger), logger);
            var accountHelper    = new GigyaAccountHelper(settingsHelper, logger, membershipHelper, settings);

            accountHelper.LoginToGigyaIfRequired();
            accountHelper.UpdateSessionExpirationCookieIfRequired(context);
        }
示例#4
0
        public PageTitleModel GetModel(string title = "", string subTitle = "")
        {
            var model = new PageTitleModel();

            if (!String.IsNullOrEmpty(title))
            {
                this.Title = title;
            }

            if (!String.IsNullOrEmpty(subTitle))
            {
                this.SubTitle = subTitle;
            }

            if (String.IsNullOrEmpty(this.Title))
            {
                var currentNode = SiteMapBase.GetCurrentNode();
                if (currentNode == null)
                {
                    model.Title = "Page Title";
                }
                else
                {
                    model.Title = SiteMapBase.GetCurrentNode().Title;
                }
            }
            else
            {
                model.Title = this.Title;
            }


            model.SubTitle = this.SubTitle;
            return(model);
        }
示例#5
0
        /// <inheritDoc/>
        public virtual FormViewModel GetViewModel()
        {
            if (this.FormId == Guid.Empty)
            {
                return(null);
            }

            var viewModel = new FormViewModel()
            {
                ViewMode       = this.ViewMode,
                CssClass       = this.CssClass,
                UseAjaxSubmit  = this.UseAjaxSubmit,
                FormId         = this.FormId.ToString("D"),
                IsMultiStep    = this.IsMultiStep,
                FormCollection = this.FormCollection
            };

            if (this.FormData != null && this.AllowRenderForm())
            {
                viewModel.FormRules = this.GetFormRulesViewModel(this.FormData);

                if (viewModel.UseAjaxSubmit)
                {
                    string baseUrl;
                    if (this.AjaxSubmitUrl.IsNullOrEmpty())
                    {
                        var currentNode = SiteMapBase.GetCurrentNode();
                        baseUrl = currentNode != null ? currentNode.Url + "/AjaxSubmit" : string.Empty;
                    }
                    else
                    {
                        baseUrl = this.AjaxSubmitUrl;
                    }

                    viewModel.AjaxSubmitUrl  = baseUrl.StartsWith("~/") ? RouteHelper.ResolveUrl(baseUrl, UrlResolveOptions.Rooted) : baseUrl;
                    viewModel.SuccessMessage = this.GetSubmitMessage(SubmitStatus.Success);

                    if (this.NeedsRedirect)
                    {
                        viewModel.RedirectUrl = this.GetRedirectPageUrl();
                        if (viewModel.RedirectUrl.StartsWith("~/"))
                        {
                            viewModel.RedirectUrl = RouteHelper.ResolveUrl(viewModel.RedirectUrl, UrlResolveOptions.Rooted);
                        }
                    }
                }
            }
            else
            {
                viewModel.Error = Res.Get <FormsResources>().TheSpecifiedFormNoLongerExists;
            }

            return(viewModel);
        }
        private static Guid GetPageWidgetId(PageManager pageManager, string controlId)
        {
            // pages
            var pageId = SiteMapBase.GetCurrentNode().PageId;
            var page   = pageManager.GetPageData(pageId);

            if (page.Template != null)
            {
                var templateControl = GetControl(page.Template.Controls, controlId);
                if (templateControl != null)
                {
                    return(templateControl.Id);
                }
            }

            if (SystemManager.IsDesignMode || SystemManager.IsPreviewMode)
            {
                var pageDraft = page.Drafts.FirstOrDefault(p => p.IsTempDraft);

                // Draft, if page is created page template is null, only draft is available
                if (page.Template == null && pageDraft.TemplateId != Guid.Empty)
                {
                    var template = pageManager.GetTemplate(pageDraft.TemplateId);
                    if (template != null)
                    {
                        var templateControl = GetControl(template.Controls, controlId);
                        if (templateControl != null)
                        {
                            return(templateControl.Id);
                        }
                    }
                }

                var control = GetControl(pageDraft.Controls, controlId);
                if (control != null)
                {
                    return(control.Id);
                }
            }
            else
            {
                var control = GetControl(page.Controls, controlId);
                if (control != null)
                {
                    return(control.Id);
                }
            }

            return(Guid.Empty);
        }
示例#7
0
        private Guid GetPageId()
        {
            var pageNode = SiteMapBase.GetCurrentNode();

            if (pageNode == null)
            {
                return(Guid.Empty);
            }

            var pageId      = SiteMapBase.GetCurrentNode().PageId;
            var pageManager = Sitefinity.Modules.Pages.PageManager.GetManager();
            var page        = pageManager.GetPageData(pageId);

            return(page.Id);
        }
        public static Guid GetWidgetId(Controller controller)
        {
            var pageManager      = PageManager.GetManager();
            var viewBagControlId = controller.ViewData[ControllerKey];

            if (viewBagControlId == null)
            {
                return(Guid.Empty);
            }

            string controlId = (string)viewBagControlId;

            // templates
            if (controller.HttpContext.Items[IsTemplate] != null && (bool)controller.HttpContext.Items[IsTemplate] == true)
            {
                // check if action is after save or cancel in template
                if (controller.HttpContext.Items[FormControlId] != null)
                {
                    return((Guid)controller.HttpContext.Items[FormControlId]);
                }

                var templateId = GetTemplateIdKey(controller.ControllerContext.HttpContext);
                var versionId  = GetVersionNumberKey(controller.ControllerContext.HttpContext);

                if (templateId != null && versionId != null)
                {
                    var template = pageManager.GetTemplate(new Guid(templateId));
                    if (template != null)
                    {
                        var           versionManager = Telerik.Sitefinity.Versioning.VersionManager.GetManager();
                        TemplateDraft draft          = new TemplateDraft();
                        versionManager.GetSpecificVersionByChangeId(draft, new Guid(versionId));

                        var control = GetControl(draft.Controls, controlId);
                        if (control != null)
                        {
                            return(control.OriginalControlId);
                        }
                    }
                }

                // check if loaded in template
                var templateData = controller.HttpContext.Items[TemplateDraftProxy] as Telerik.Sitefinity.Modules.Pages.TemplateDraftProxy;
                if (templateData != null)
                {
                    var template = pageManager.GetTemplate(templateData.ParentItemId);
                    if (template != null)
                    {
                        if (SystemManager.IsDesignMode || SystemManager.IsPreviewMode)
                        {
                            var control = GetControl(template.Drafts.FirstOrDefault(p => p.IsTempDraft).Controls, controlId);
                            if (control != null)
                            {
                                return(control.Id);
                            }
                        }
                        else
                        {
                            var control = GetControl(template.Controls, controlId);
                            if (control != null)
                            {
                                return(control.Id);
                            }
                        }
                    }
                }
            }
            else
            {
                // pages
                var pageId = SiteMapBase.GetCurrentNode().PageId;
                var page   = pageManager.GetPageData(pageId);

                if (page.Template != null)
                {
                    var templateControl = GetControl(page.Template.Controls, controlId);
                    if (templateControl != null)
                    {
                        return(templateControl.Id);
                    }
                }

                if (SystemManager.IsDesignMode || SystemManager.IsPreviewMode)
                {
                    var pageDraft = page.Drafts.FirstOrDefault(p => p.IsTempDraft);

                    // Draft, if page is created page template is null, only draft is avalaible
                    if (page.Template == null && pageDraft.TemplateId != Guid.Empty)
                    {
                        var template = pageManager.GetTemplate(pageDraft.TemplateId);
                        if (template != null)
                        {
                            var templateControl = GetControl(template.Controls, controlId);
                            if (templateControl != null)
                            {
                                return(templateControl.Id);
                            }
                        }
                    }

                    var control = GetControl(pageDraft.Controls, controlId);
                    if (control != null)
                    {
                        return(control.Id);
                    }
                }
                else
                {
                    var control = GetControl(page.Controls, controlId);
                    if (control != null)
                    {
                        return(control.Id);
                    }
                }
            }

            return(Guid.Empty);
        }
示例#9
0
 /// <summary>
 /// Resolves the current sitemap node.
 /// </summary>
 /// <returns></returns>
 protected virtual PageSiteNode ResolveCurrentSitemapNode()
 {
     return(SiteMapBase.GetCurrentNode());
 }
示例#10
0
        /// <inheritDoc/>
        public virtual FormViewModel GetViewModel()
        {
            if (this.FormId == Guid.Empty)
            {
                return(null);
            }

            var marketoSettings = new MarketoSettings()
            {
                SyncFormFieldsToLeadFields = this.GetSyncFormFieldsToLeadFields(this.FormData),
                DoSpecificWebCalls         = this.GetDoSpecificWebCalls(this.FormData)
            };

            var jsonSerializerSettings = new JsonSerializerSettings()
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };
            var viewModel = new FormViewModel()
            {
                ViewMode        = this.ViewMode,
                CssClass        = this.CssClass,
                UseAjaxSubmit   = this.UseAjaxSubmit,
                FormId          = this.FormId.ToString("D"),
                IsMultiStep     = this.IsMultiStep,
                FormCollection  = this.FormCollection,
                MarketoSettings = JsonConvert.SerializeObject(marketoSettings, Formatting.None, jsonSerializerSettings)
            };

            if (this.FormData != null && this.AllowRenderForm())
            {
                viewModel.FormRules = this.GetFormRulesViewModel(this.FormData);

                if (viewModel.UseAjaxSubmit)
                {
                    string baseUrl;
                    if (this.AjaxSubmitUrl.IsNullOrEmpty())
                    {
                        var currentNode = SiteMapBase.GetCurrentNode();
                        baseUrl = currentNode != null ? currentNode.Url + "/AjaxSubmit" : string.Empty;
                    }
                    else
                    {
                        baseUrl = this.AjaxSubmitUrl;
                    }

                    viewModel.AjaxSubmitUrl  = baseUrl.StartsWith("~/") ? RouteHelper.ResolveUrl(baseUrl, UrlResolveOptions.Rooted) : baseUrl;
                    viewModel.SuccessMessage = this.GetSubmitMessage(SubmitStatus.Success);

                    if (this.NeedsRedirect)
                    {
                        viewModel.RedirectUrl = this.GetRedirectPageUrl();
                        if (viewModel.RedirectUrl.StartsWith("~/"))
                        {
                            viewModel.RedirectUrl = RouteHelper.ResolveUrl(viewModel.RedirectUrl, UrlResolveOptions.Rooted);
                        }
                    }
                }
            }
            else
            {
                viewModel.Error = Res.Get <FormsResources>().TheSpecifiedFormNoLongerExists;
            }

            return(viewModel);
        }