Esempio n. 1
0
        private void InitPage()
        {
            var settings        = SettingsMapper.GetSettings();
            var rootMediaDetail = BaseMapper.GetDataModel().MediaDetails.FirstOrDefault(i => i.MediaType.Name == MediaTypeEnum.RootPage.ToString() && i.LanguageID == AdminBasePage.CurrentLanguage.ID);

            if (rootMediaDetail == null)
            {
                CreateItem.Visible = true;
            }

            if (settings.EnableGlossaryTerms)
            {
                GlossaryTermsNavItem.Visible = true;
            }

            if (numberOfActiveLanguages < 2)
            {
                LanguageSwitcher.Visible = false;
            }
            else
            {
                LanguageSwitcher.Visible = true;
            }

            //AdminBasePage.SelectedMedia = null;
            //AdminBasePage.SelectedMediaDetail = null;

            CreateItem.NavigateUrl = $"{URIHelper.BaseUrl}Admin/Views/PageHandlers/Media/Create.aspx";
        }
Esempio n. 2
0
        protected void Delete_Click(object sender, EventArgs e)
        {
            var field = GetDataItemFromSender((Control)sender);

            if (field != null && field.ID != 0)
            {
                var mediaDetailFields = BaseMapper.GetDataModel().Fields.Where(i => i.ID == field.ID);

                foreach (MediaDetailField mediaDetailField in mediaDetailFields)
                {
                    var fieldAssociations = mediaDetailField.FieldAssociations.ToList();

                    foreach (var fieldAssociation in fieldAssociations)
                    {
                        BaseMapper.GetDataModel().FieldAssociations.Remove(fieldAssociation);
                    }

                    BaseMapper.DeleteObjectFromContext(mediaDetailField);
                }

                var returnObj = MediaDetailsMapper.Update(mediaDetail);

                if (!returnObj.IsError)
                {
                    UpdatedFieldsFromObject(new MediaDetailField());
                    BindItemList();
                }
                else
                {
                    BasePage.DisplayErrorMessage("Error", returnObj.Error);
                }
            }
        }
Esempio n. 3
0
        public void BindGlobalFields()
        {
            var globalFields = BaseMapper.GetDataModel().MediaDetails.Where(i => i.MediaType.ShowInSiteTree && i.HistoryVersionNumber == 0 && i.Fields.Any(j => j.IsGlobalField)).SelectMany(i => i.Fields.Where(j => j.IsGlobalField)).ToList();

            GlobalFields.DataSource = globalFields;
            GlobalFields.DataBind();
        }
        public void ReOrderMediaFields(List <FrameworkLibrary.MediaDetailField> items)
        {
            UserMustBeInRole(RoleEnum.Developer);

            var index = 0;

            foreach (var item in items)
            {
                var mediaField = BaseMapper.GetDataModel().Fields.SingleOrDefault(i => i.ID == item.ID);

                if (mediaField != null)
                {
                    mediaField.OrderIndex = index;

                    index++;
                }

                if (mediaField is MediaTypeField)
                {
                    var mediaTypeField = mediaField as MediaTypeField;

                    foreach (var mediaDetailField in mediaTypeField.MediaDetailFields)
                    {
                        mediaDetailField.OrderIndex = mediaTypeField.OrderIndex;
                    }
                }
            }

            var returnObj = BaseMapper.SaveDataModel();
            var json      = returnObj.ToJson();

            WriteJSON(json);
        }
Esempio n. 5
0
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            if (!BaseMapper.GetDataModel().MediaDetails.Any())
            {
                var rootMediaType = MediaTypesMapper.GetByEnum(MediaTypeEnum.RootPage);

                if (rootMediaType != null)
                {
                    MediaTypeSelector.SetMediaTypes(new List <MediaType>()
                    {
                        rootMediaType
                    });
                }
            }
            else
            {
                if (SelectedMedia != null)
                {
                    MediaType mediaType = MediaTypesMapper.GetByID(MediaDetailsMapper.GetAtleastOneByMedia(SelectedMedia, CurrentLanguage).MediaTypeID);
                    MediaTypeSelector.SetMediaTypes(mediaType.MediaTypes);
                }
            }
        }
Esempio n. 6
0
        protected void Deploy_Click(object sender, EventArgs e)
        {
            try
            {
                var remoteConnectionStringSetting = FrameworkBaseMedia.PrepareConnectionSettings(WebConfigurationManager.ConnectionStrings[DeployToEnvironment.SelectedValue]);
                //var localConnectionStringSetting = FrameworkBaseMedia.PrepareConnectionSettings(AppSettings.GetConnectionSettings());

                var localDataModel  = BaseMapper.GetDataModel();
                var remoteDataModel = BaseMapper.GetDataModel(true, true, remoteConnectionStringSetting);

                var localMediaDetails  = localDataModel.MediaDetails.Where(i => i.HistoryVersionNumber == 0 && i.MediaType.ShowInSiteTree && i.MediaType.Name != MediaTypeEnum.RootPage.ToString()).ToList();
                var remoteMediaDetails = remoteDataModel.MediaDetails.Where(i => i.HistoryVersionNumber == 0 && i.MediaType.ShowInSiteTree && i.MediaType.Name != MediaTypeEnum.RootPage.ToString()).ToList();

                var localSettings  = localDataModel.AllSettings.FirstOrDefault();
                var remoteSettings = remoteDataModel.AllSettings.FirstOrDefault();

                if (localSettings.GlobalCodeInBody != remoteSettings.GlobalCodeInBody)
                {
                    AddMessage("Settings", $"The setting: 'GlobalCodeInBody' is different");
                }

                if (localSettings.GlobalCodeInHead != remoteSettings.GlobalCodeInHead)
                {
                    AddMessage("Settings", $"The setting: 'GlobalCodeInHead' is different");
                }

                foreach (var localMediaDetail in localMediaDetails)
                {
                    var remoteMediaDetail = remoteMediaDetails.FirstOrDefault(i => i.MediaID == localMediaDetail.MediaID && i.LanguageID == localMediaDetail.LanguageID);

                    if (remoteMediaDetail != null)
                    {
                        CompareLocalAndRemoteMediaDetail(localMediaDetail, remoteMediaDetail);
                    }
                    else
                    {
                        var found = remoteMediaDetails.FirstOrDefault(i => i.CachedVirtualPath == localMediaDetail.CachedVirtualPath && i.LanguageID == localMediaDetail.LanguageID);

                        if (found != null)
                        {
                            //AddMessage("Different MediaID's but the same cached virtual path", $"Local: {localMediaDetail.CachedVirtualPath} is '{localMediaDetail.MediaID}' | Remote: {found.CachedVirtualPath}  is '{found.MediaID}'");
                            CompareLocalAndRemoteMediaDetail(localMediaDetail, found);
                        }
                        else
                        {
                            AddMessage("Does not exist on remote", $"{localMediaDetail.CachedVirtualPath}");
                        }
                    }
                }

                DeployMessages.DataSource = _deployMessages;
                DeployMessages.DataBind();
            }
            catch (Exception ex)
            {
                ErrorHelper.LogException(ex);

                DisplayErrorMessage(ex.Message, ErrorHelper.CreateError(ex));
            }
        }
Esempio n. 7
0
        protected void Page_Init(object sender, EventArgs e)
        {
            if (Items == null)
            {
                Items = BaseMapper.GetDataModel().MasterPages.OrderBy(i => i.Name).ToList();
            }

            Bind();
        }
Esempio n. 8
0
        private void UpdateVisibility()
        {
            var id    = long.Parse(FieldID.Value);
            var field = (MediaDetailField)BaseMapper.GetDataModel().Fields.Find(id);

            if (field != null)
            {
                BindVisibility(field);
            }
        }
Esempio n. 9
0
        protected void Page_Init(object sender, EventArgs e)
        {
            this.Section.Text = this.Page.Title = "Manage Permission";

            if (Items == null)
            {
                Items = BaseMapper.GetDataModel().Permissions.OrderBy(i => i.Name).ToList();
            }

            Bind();
        }
Esempio n. 10
0
        protected void Page_Init(object sender, EventArgs e)
        {
            this.Section.Text = this.Page.Title = "Manage Glossary Terms";

            if (Items == null)
            {
                Items = BaseMapper.GetDataModel().GlossaryTerms.OrderBy(i => i.Term).ToList();
            }

            Bind();
        }
Esempio n. 11
0
        public MediaDetailField GetField()
        {
            if (_field != null)
            {
                return(_field);
            }

            _field = (MediaDetailField)BaseMapper.GetDataModel().Fields.Find(FieldID);

            if (_field == null)
            {
                _field = new MediaDetailField();
            }

            return(_field);
        }
Esempio n. 12
0
        public void GoogleSiteMap()
        {
            var mediaDetails = BaseMapper.GetDataModel().MediaDetails.Where(i => i.HistoryVersionNumber == 0 && !i.IsDeleted && ((i.ShowInMenu) || (i.MediaType.Name == "Blog" || i.MediaType.Name == "BlogPost")) && i.PublishDate < DateTime.Now && i.MediaType.ShowInSiteTree).ToList().Where(i => i.CanRender);
            var xmlEntries   = "";

            foreach (var mediaDetail in mediaDetails)
            {
                xmlEntries += ConvertMediaDetailToSiteMapXmlEntry(mediaDetail);
            }

            var xml = $@"<?xml version='1.0' encoding='UTF-8'?>
<urlset xmlns='http://www.sitemaps.org/schemas/sitemap/0.9'> 
    {xmlEntries}
</urlset>";

            WriteXML(xml);
        }
Esempio n. 13
0
        public int ReOrderMediaFields(List <FrameworkLibrary.MediaDetailField> items)
        {
            var index = 0;

            foreach (var item in items)
            {
                var mediaField = BaseMapper.GetDataModel().MediaDetailFields.SingleOrDefault(i => i.ID == item.ID);

                if (mediaField != null)
                {
                    mediaField.OrderIndex = index;

                    index++;
                }
            }

            return(BaseMapper.GetDataModel().SaveChanges());
        }
Esempio n. 14
0
        protected void Page_Init(object sender, EventArgs e)
        {
            this.Section.Text = this.Page.Title = "Manage Users";

            if (Items == null)
            {
                if (CurrentUser.IsInRole(RoleEnum.Developer))
                {
                    Items = BaseMapper.GetDataModel().Users.OrderBy(i => i.UserName).ToList();
                }
                else
                {
                    Items = BaseMapper.GetDataModel().Users.OrderBy(i => i.UserName).ToList().Where(i => !i.IsInRole(RoleEnum.Developer)).ToList();
                }
            }

            Bind();
        }
        private void SaveToDB(string value)
        {
            var obj = StringHelper.JsonToObject <List <JsonObj> >(value);

            if (obj == null)
            {
                return;
            }

            var field = GetField();

            var newIds = StringHelper.ObjectToJson(obj.Select(i => i.id).ToList());
            var oldIds = StringHelper.ObjectToJson(field.FieldAssociations.Select(i => i.AssociatedMediaDetailID).ToList());

            if (newIds == oldIds)
            {
                return;
            }

            var fieldAssociations = field.FieldAssociations.ToList();

            foreach (var item in fieldAssociations)
            {
                BaseMapper.DeleteObjectFromContext(item);
            }

            var orderIndex = 0;

            foreach (var item in obj)
            {
                var mediaDetail = (MediaDetail)MediaDetailsMapper.GetByID(item.id);

                if (mediaDetail != null)
                {
                    field.FieldAssociations.Add(new FieldAssociation()
                    {
                        MediaDetail = mediaDetail, MediaDetailField = field, OrderIndex = orderIndex
                    });
                    orderIndex++;
                }
            }

            var returnObj = BaseMapper.GetDataModel().SaveChanges();
        }
Esempio n. 16
0
        private void BindItems()
        {
            if (ParentMediaID == 0 && MediaTypeID == 0)
            {
                ParentMediaID = AdminBasePage.SelectedMedia.ID;
            }

            var parentMedia = MediasMapper.GetByID(ParentMediaID);
            IEnumerable <IMediaDetail> mediaDetailItems = new List <IMediaDetail>();

            if (parentMedia != null)
            {
                var liveMediaDetail = parentMedia.GetLiveMediaDetail();

                if (MediaTypeID > 0)
                {
                    mediaDetailItems = liveMediaDetail.ChildMediaDetails.Where(i => i.MediaTypeID == MediaTypeID && i.HistoryVersionNumber == 0 && i.MediaType.ShowInSiteTree && !i.IsDeleted);
                }
                else
                {
                    mediaDetailItems = liveMediaDetail.ChildMediaDetails.Where(i => i.HistoryVersionNumber == 0 && i.MediaType.ShowInSiteTree && !i.IsDeleted);
                }
            }

            else
            {
                if (MediaTypeID > 0)
                {
                    mediaDetailItems = BaseMapper.GetDataModel().MediaDetails.Where(i => i.MediaTypeID == MediaTypeID && i.HistoryVersionNumber == 0 && i.MediaType.ShowInSiteTree && !i.IsDeleted);
                }
            }

            if (ShowInMenu != ShowStatus.Any)
            {
                mediaDetailItems = mediaDetailItems.Where(i => i.ShowInMenu == bool.Parse(ShowInMenu.ToString()));
            }

            ItemsList.DataSource     = mediaDetailItems.ToList();
            ItemsList.DataTextField  = "SectionTitle";
            ItemsList.DataValueField = "ID";
            ItemsList.DataBind();
        }
Esempio n. 17
0
        private void Bind(string searchText = "")
        {
            var mediaId = selectedItem.Media.ID;

            if (string.IsNullOrEmpty(searchText))
            {
                listItems = BaseMapper.GetDataModel().MediaDetails.Where(i => i.Media.ParentMediaID == mediaId && i.MediaType.ShowInSiteTree && i.HistoryVersionNumber == 0).OrderByDescending(i => i.DateLastModified).ToList <IMediaDetail>();
            }
            else
            {
                listItems = BaseMapper.GetDataModel().MediaDetails.Where(i => i.Media.ParentMediaID == mediaId && i.MediaType.ShowInSiteTree && i.HistoryVersionNumber == 0 && i.LinkTitle.Contains(searchText)).OrderByDescending(i => i.DateLastModified).ToList <IMediaDetail>();
            }

            /*if(listItems.Count > 0)
             * {
             *  SearchPanel.Visible = true;
             * }*/

            ItemList.DataSource = listItems;
            ItemList.DataBind();
        }
        public void SearchForNodes(string filterText)
        {
            filterText = filterText.ToLower().Trim();
            var foundItems = BaseMapper.GetDataModel().MediaDetails.Where(i => i.MediaType.ShowInSiteTree &&
                                                                          i.HistoryVersionNumber == 0 &&
                                                                          i.LanguageID == AdminBasePage.CurrentLanguage.ID &&
                                                                          (i.MediaID.ToString() == filterText ||
                                                                           i.Fields.FirstOrDefault(j => j.FieldCode == "MainContent").FieldValue.ToLower().Contains(filterText) ||
                                                                           i.Fields.FirstOrDefault(j => j.FieldCode == "ShortDescription").FieldValue.ToLower().Contains(filterText) ||
                                                                           i.Fields.FirstOrDefault(j => j.FieldCode == "SectionTitle").FieldValue.ToLower().Contains(filterText) ||
                                                                           i.MainLayout.ToLower().Contains(filterText) ||
                                                                           i.MediaType.MainLayout.ToLower().Contains(filterText) ||
                                                                           i.Fields.Any(j => (j.FieldAssociations.Count == 0 && j.FieldValue.ToLower().Contains(filterText)) ||
                                                                                        j.FieldAssociations.Any(k => !k.MediaDetail.MediaType.ShowInSiteTree &&
                                                                                                                (k.MediaDetail.Fields.FirstOrDefault(l => l.FieldCode == "SectionTitle").FieldValue.ToLower().Contains(filterText) ||
                                                                                                                 k.MediaDetail.Fields.FirstOrDefault(l => l.FieldCode == "MainContent").FieldValue.ToLower().Contains(filterText) ||
                                                                                                                 k.MediaDetail.Fields.FirstOrDefault(l => l.FieldCode == "MainLayout").FieldValue.ToLower().Contains(filterText))
                                                                                                                ))
                                                                          )).ToList();

            var jsTreeNodes = foundItems.Select(i => GetJsTreeNode(i));

            var newJsTreeNodes = new List <JsTreeNode>();

            foreach (var node in jsTreeNodes)
            {
                node.parent         = "#";
                node.state.opened   = false;
                node.state.selected = false;
                node.children       = false;

                newJsTreeNodes.Add(node);
            }

            WriteJSON(StringHelper.ObjectToJson(newJsTreeNodes));
        }
        public void GetChildNodes(long id)
        {
            var rootNode = BaseMapper.GetDataModel().MediaDetails.FirstOrDefault(i => i.HistoryForMediaDetail == null && i.MediaID == id);

            if (rootNode != null)
            {
                IEnumerable <IMediaDetail> childMediaDetails = MediaDetailsMapper.GetAtleastOneChildByMedia(rootNode.Media, AdminBasePage.CurrentLanguage).ToList();

                //var childMediaDetails = BaseMapper.GetDataModel().MediaDetails.Where(i => i.HistoryVersionNumber == 0 && i.Media.ParentMediaID == rootNode.MediaID && i.ID != rootNode.ID && i.MediaType.ShowInSiteTree && i.LanguageID == AdminBasePage.CurrentLanguage.ID).OrderBy(i => i.Media.OrderIndex).ToList();

                /*childMediaDetails = childMediaDetails.Where(i =>
                 * {
                 *  if(MediaDetailsMapper.CanAccessMediaDetail(i, FrameworkSettings.CurrentUser).IsError)
                 *  {
                 *      return false;
                 *  }
                 *
                 *  return true;
                 * });*/

                var jsTreeNodes = childMediaDetails.Select(i => GetJsTreeNode(i));
                WriteJSON(StringHelper.ObjectToJson(jsTreeNodes));
            }
        }
Esempio n. 20
0
        protected void Page_Init(object sender, EventArgs e)
        {
            var templateTopAndBottomSegments = CurrentMediaDetail.GetTemplateTopAndBottomSegments(this);

            if (templateTopAndBottomSegments.Count > 1)
            {
                TemplateTopSegment.Controls.Add(templateTopAndBottomSegments.ElementAt(0));
                TemplateBottomSegment.Controls.Add(templateTopAndBottomSegments.ElementAt(1));
            }

            var blogPosts  = BaseMapper.GetDataModel().MediaDetails.Where(i => i.MediaType.Name == "BlogPost" && i.HistoryVersionNumber == 0);
            var categories = BaseMapper.GetDataModel().MediaDetails.Where(i => i.MediaType.Name == "BlogCategory" && i.HistoryVersionNumber == 0);

            BlogCategories.DataSource = categories.ToList().Where(i => i.CanRender).ToList();
            BlogCategories.DataBind();

            if (CurrentMediaDetail.MediaType.Name == "BlogCategory")
            {
                blogPosts = blogPosts.Where(i => i.Media.ParentMediaID == CurrentMediaDetail.MediaID);
            }

            BlogPosts.DataSource = blogPosts.ToList().Where(i => i.CanRender).OrderByDescending(i => i.PublishDate).ToList();
            BlogPosts.DataBind();
        }
        public string GetDataJson()
        {
            var media           = MediasMapper.GetByID(ParentMediaID);
            var autoSuggestList = new List <AutoSuggest>();
            IEnumerable <IMediaDetail> mediaDetailItems = new List <IMediaDetail>();

            if (media != null)
            {
                var liveMediaDetail = media.GetLiveMediaDetail();

                if (MediaTypeID > 0)
                {
                    mediaDetailItems = liveMediaDetail.ChildMediaDetails.Where(i => i.MediaTypeID == MediaTypeID && i.HistoryVersionNumber == 0 && i.MediaType.ShowInSiteTree && !i.IsDeleted);
                }
                else
                {
                    mediaDetailItems = liveMediaDetail.ChildMediaDetails.Where(i => i.HistoryVersionNumber == 0 && i.MediaType.ShowInSiteTree && !i.IsDeleted);
                }
            }
            else
            {
                if (MediaTypeID > 0)
                {
                    mediaDetailItems = BaseMapper.GetDataModel().MediaDetails.Where(i => i.MediaTypeID == MediaTypeID && i.HistoryVersionNumber == 0 && i.MediaType.ShowInSiteTree && !i.IsDeleted);
                }
            }

            if (ShowInMenu != ShowStatus.Any)
            {
                mediaDetailItems = mediaDetailItems.Where(i => i.ShowInMenu == bool.Parse(ShowInMenu.ToString()));
            }

            autoSuggestList = GetAutoSuggestList(mediaDetailItems);

            return(StringHelper.ObjectToJson(autoSuggestList));
        }
        private void UpdateTreeNode(JsTreeNode node, IMediaDetail detail)
        {
            if (detail == null)
            {
                return;
            }

            node.id     = detail.MediaID.ToString();
            node.parent = (detail.Media.ParentMediaID == null) ? "#" : detail.Media.ParentMediaID.ToString();
            node.text   = detail.SectionTitle;

            //node.children =( MediaDetailsMapper.GetAtleastOneChildByMedia(detail.Media, AdminBasePage.CurrentLanguage).Where(i => i.MediaType.ShowInSiteTree).Count() > 0);
            node.children = (BaseMapper.GetDataModel().MediaDetails.Count(i => i.MediaType.ShowInSiteTree && i.HistoryVersionNumber == 0 && i.Media.ParentMediaID == detail.MediaID) > 0);

            node.text = detail.SectionTitle.ToString();
            //node.Attributes.Add("FrontEndUrl", detail.AbsoluteUrl);

            var nodeText = "";

            if (detail.LanguageID != AdminBasePage.CurrentLanguage.ID)
            {
                nodeText            = $"{detail.LinkTitle} - {LanguagesMapper.GetByID(detail.Language.ID).Name} ({node.id})";
                node.li_attr._class = "doesNotExistInLanguage";
            }
            else
            {
                nodeText = $"{detail.LinkTitle} <small>({detail.MediaID})</small>";
            }

            if (detail.IsDeleted)
            {
                node.li_attr._class += " isDeleted";
            }

            if (detail.WillPublish)
            {
                node.li_attr._class += " willPublish";

                var autoPublishCode = $"<i class='fa fa-clock-o' aria-hidden='true' title='This page is set to auto-publish at: {detail.PublishDate}'></i> ";

                nodeText += $"<small class='willPublishWrapper'>{autoPublishCode}Will Publish</small>";
            }

            if (detail.IsPublished && detail.WillExpire)
            {
                node.li_attr._class += " willExpire";

                var autoPublishCode = $"<i class='fa fa-clock-o' aria-hidden='true' title='This page is set to auto-expire at: {detail.ExpiryDate}'></i> ";

                nodeText += $"<small class='willExpireWrapper'>{autoPublishCode}Will Expire</small>";
            }

            if ((!detail.ShowInMenu) && (!detail.RenderInFooter))
            {
                node.li_attr._class += " isHidden";
            }


            if (detail.HasExpired)
            {
                node.li_attr._class += " hasExpired";

                nodeText += $"<small class='hasExpiredWrapper'>Has Expired</small>";
            }
            else
            {
                if (!detail.IsPublished && !detail.WillPublish)
                {
                    node.li_attr._class += " unPublished";

                    nodeText += $"<small class='unPublishedWrapper'>UnPublished</small>";
                }
            }

            if (AdminBasePage.SelectedMediaDetail != null && AdminBasePage.SelectedMediaDetail.ID == detail.ID)
            {
                node.li_attr._class += " selected";
            }

            var draft = detail.GetLatestDraft();

            if (detail.HasDraft && draft != null)
            {
                node.li_attr._class += " hasDraft";

                var autoPublishCode = "";

                if (draft.DateLastModified > detail.DateLastModified)
                {
                    node.li_attr._class += " draftIsNewer";
                }

                if ((draft.PublishDate - detail.PublishDate) > TimeSpan.FromSeconds(10))
                {
                    autoPublishCode = $"<i class='fa fa-clock-o' aria-hidden='true' title='This draft is set to auto-publish at: {draft.PublishDate}'></i> ";
                }

                nodeText += $"<small class='hasDraftWrapper'>{autoPublishCode}Has Draft</small>";
            }

            var pendingComments = detail.Media.Comments.Count(i => i.Status == StatusEnum.Pending.ToString() && i.LanguageID == detail.LanguageID);

            if (pendingComments > 0)
            {
                node.li_attr._class += " hasPendingComments";
                nodeText            += $"<small class='hasPendingCommentsWrapper'>Pending Comments</small>";
            }

            if (detail.MediaType.GetRoles().Count > 0 || detail.Media.RolesMedias.Count > 0)
            {
                var fontAwsomeClasses = "fa";

                node.li_attr._class += " restricted";
                if (MediaDetailsMapper.CanAccessMediaDetail(detail, FrameworkSettings.CurrentUser).IsError)
                {
                    fontAwsomeClasses += " fa-lock";
                }
                else
                {
                    fontAwsomeClasses += " fa-unlock";
                }

                nodeText += $"<small class='restrictedWrapper'><i class='fa {fontAwsomeClasses}' aria-hidden='true'></i></small>";
            }

            node.text = nodeText;

            //node.LinkAttributes.Add("data-frontendurl", detail.Media.PermaLink);
            node.a_attr.frontendurl    = detail.AbsoluteUrl;
            node.li_attr.mediaDetailId = detail.ID.ToString();

            node.a_attr.href = URIHelper.ConvertToAbsUrl(WebApplication.BasePage.GetAdminUrl(detail.MediaTypeID, detail.MediaID));

            if (detail?.MediaType?.Name == "Website" || detail?.MediaType?.Name == "RootPage")
            {
                node.state.opened = true;
            }

            IEnumerable <Media> parentItems = new List <Media>();

            if (AdminBasePage.SelectedMedia != null)
            {
                parentItems = MediaDetailsMapper.GetAllParentMedias(AdminBasePage.SelectedMedia);

                if (parentItems.Any(i => i.ID == detail.MediaID))
                {
                    node.state.opened = true;
                }
            }

            if (detail.MediaID == AdminBasePage.SelectedMedia?.ID)
            {
                node.state.opened   = true;
                node.state.selected = true;
            }
        }
        public void GetRootNodes()
        {
            var rootNode = BaseMapper.GetDataModel().MediaDetails.FirstOrDefault(i => i.HistoryForMediaDetail == null && i.Media.ParentMedia == null && i.MediaType.Name == MediaTypeEnum.RootPage.ToString());

            WriteJSON(StringHelper.ObjectToJson(GetJsTreeNode(rootNode)));
        }
Esempio n. 24
0
 protected void Page_Init(object sender, EventArgs e)
 {
     CommentsList.DataSource = BaseMapper.GetDataModel().Comments.Where(i => i.Status == Status.ToString() && i.LanguageID == AdminBasePage.CurrentLanguage.ID).ToList();
     CommentsList.DataBind();
 }
Esempio n. 25
0
        public IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            RedisCacheHelper.SetRedisCacheConnectionString(AppSettings.RedisCacheConnectionString);
            FileCacheHelper.SetFileSystemCacheDirPath(AppSettings.FileSystemCacheDirPath);

            virtualPath = URIHelper.GetCurrentVirtualPath().ToLower();

            var queryString = HttpContext.Current.Request.QueryString.ToString();

            queryString = System.Web.HttpUtility.UrlDecode(queryString);


            if (!Request.Path.EndsWith("/") || ((virtualPath != "~/") && (!virtualPath.EndsWith("/"))))
            {
                var path = Request.Path + "/";

                if (!string.IsNullOrEmpty(queryString))
                {
                    path = path + "?" + queryString;
                }

                HttpContext.Current.Response.RedirectPermanent(path);
            }

            Settings cmsSettings            = null;
            bool     isAttemptingAdminLogin = false;

            if ((virtualPath != "~/login/") && (virtualPath != "~/admin/") && string.IsNullOrEmpty(Request.QueryString["format"]))
            {
                cmsSettings = SettingsMapper.GetSettings();

                if (cmsSettings != null)
                {
                    var isSiteOnline = cmsSettings.IsSiteOnline();

                    if (isSiteOnline)
                    {
                        if (virtualPath.Contains(cmsSettings.SiteOfflineUrl))
                        {
                            Response.Redirect("~/");
                        }

                        AttemptToLoadFromCache();
                    }
                    else
                    {
                        if (!virtualPath.Contains(cmsSettings.SiteOfflineUrl))
                        {
                            Response.Redirect(cmsSettings.SiteOfflineUrl);
                        }
                    }
                }
                else
                {
                    AttemptToLoadFromCache();
                }
            }
            else
            {
                isAttemptingAdminLogin = true;
            }

            var languageSegment = FrameworkSettings.GetCurrentLanguage().UriSegment;

            if (LanguagesMapper.GetAllActive().Count() > 1 && !Request.Url.PathAndQuery.Contains($"/{languageSegment}/"))
            {
                var url = URIHelper.ConvertToAbsUrl("/" + languageSegment + Request.Url.PathAndQuery);
                Response.RedirectPermanent(url, true);
            }

            var segments = URIHelper.GetUriSegments(virtualPath).ToList();

            string firstSegment = "";

            if (segments.Count > 0)
            {
                firstSegment = segments[0];

                var language = LanguagesMapper.GetAllActive().SingleOrDefault(i => i.UriSegment == firstSegment);

                if (language != null)
                {
                    FrameworkSettings.SetCurrentLanguage(language);
                }
            }

            if (!isAttemptingAdminLogin && AppSettings.EnableUrlRedirectRules)
            {
                var path = virtualPath;

                if (!string.IsNullOrEmpty(queryString))
                {
                    path = path + "?" + queryString;
                }

                var redirectRule = UrlRedirectRulesMapper.GetRuleForUrl(path);

                if (redirectRule != null)
                {
                    var newUrl = redirectRule.RedirectToUrl;

                    if (newUrl.Contains("{"))
                    {
                        newUrl = MediaDetailsMapper.ParseSpecialTags(redirectRule, newUrl);
                    }

                    newUrl = URIHelper.ConvertToAbsUrl(newUrl);

                    var possibleLoopRules      = UrlRedirectRulesMapper.GetRulesFromUrl(URIHelper.ConvertAbsUrlToTilda(newUrl));
                    var foundActiveVirtualPath = MediaDetailsMapper.GetByVirtualPath(path);

                    if (possibleLoopRules.Any())
                    {
                        foreach (var rule in possibleLoopRules)
                        {
                            var returnObj = MediaDetailsMapper.DeletePermanently(rule);
                        }
                    }

                    if (foundActiveVirtualPath != null)
                    {
                        var returnObj = MediaDetailsMapper.DeletePermanently(redirectRule);
                    }

                    if (Request.QueryString.Count > 0)
                    {
                        newUrl += "?" + Request.QueryString;
                    }

                    if (redirectRule.Is301Redirect)
                    {
                        Response.RedirectPermanent(newUrl);
                    }
                    else
                    {
                        Response.Redirect(newUrl);
                    }
                }
            }

            if (!File.Exists(HttpContext.Current.Server.MapPath(virtualPath)) && !virtualPath.Contains(ParserHelper.OpenToken) && !virtualPath.Contains(ParserHelper.CloseToken))
            {
                string viewPath = "";

                long mediaDetailId = 0;
                long.TryParse(requestContext.HttpContext.Request["MediaDetailID"], out mediaDetailId);

                long mediaId = 0;
                long.TryParse(requestContext.HttpContext.Request["MediaID"], out mediaId);

                MediaDetail detail = null;

                if (mediaDetailId == 0 && mediaId == 0)
                {
                    FrameworkSettings.Current = FrameworkBaseMedia.GetInstanceByVirtualPath(virtualPath, true);
                    detail = (MediaDetail)FrameworkSettings.Current.CurrentMediaDetail;
                }
                else if (mediaDetailId != 0)
                {
                    var mediaDetail = MediaDetailsMapper.GetByID(mediaDetailId);

                    FrameworkSettings.Current = FrameworkBaseMedia.GetInstanceByMediaDetail(mediaDetail);
                    detail = (MediaDetail)FrameworkSettings.Current.CurrentMediaDetail;
                }
                else if (mediaId != 0)
                {
                    var media = MediasMapper.GetByID(mediaId);

                    FrameworkSettings.Current = FrameworkBaseMedia.GetInstanceByMedia(media);
                    detail = (MediaDetail)FrameworkSettings.Current.CurrentMediaDetail;
                }

                /*if (detail != null && !detail.CanUserAccessSection(FrameworkSettings.CurrentUser))
                 * {
                 *  FormsAuthentication.RedirectToLoginPage();
                 * }*/

                /*if (detail != null)
                 * {
                 *  var absUrlBase = URIHelper.ConvertAbsUrlToTilda(detail.AbsoluteUrl).Replace("~", "");
                 *  var absPathBase = URIHelper.ConvertAbsUrlToTilda(Request.Url.AbsolutePath).Replace("~", "");
                 *
                 *  if (absUrlBase != absPathBase)
                 *  {
                 *      Response.Redirect(detail.AbsoluteUrl + Request.Url.Query);
                 *  }
                 * }*/

                if (detail != null)
                {
                    if (detail.ForceSSL || AppSettings.ForceSSL)
                    {
                        URIHelper.ForceSSL();
                    }
                }
                else
                {
                    var currentLanguageId = FrameworkSettings.GetCurrentLanguage().ID;

                    var historyVersion = BaseMapper.GetDataModel().MediaDetails.FirstOrDefault(i => i.LanguageID == currentLanguageId && i.CachedVirtualPath == virtualPath && i.MediaType.ShowInSiteTree && i.HistoryVersionNumber != 0 && i.HistoryForMediaDetail != null);

                    if (historyVersion != null && historyVersion.VirtualPath != historyVersion.HistoryForMediaDetail.VirtualPath)
                    {
                        var foundRedirectUrl = UrlRedirectRulesMapper.GetRuleForUrl(virtualPath);

                        if (foundRedirectUrl == null)
                        {
                            var urlRedirectRule = UrlRedirectRulesMapper.CreateUrlRedirect(virtualPath, historyVersion.HistoryForMediaDetail.Media);

                            if (urlRedirectRule != null)
                            {
                                var returnObj = UrlRedirectRulesMapper.Insert(urlRedirectRule);
                                HttpContext.Current.Response.RedirectPermanent(historyVersion.HistoryForMediaDetail.CachedVirtualPath);
                            }
                            else
                            {
                                HttpContext.Current.Response.RedirectPermanent("/");
                            }
                        }
                    }
                    else
                    {
                        HttpContext.Current.Response.RedirectPermanent("/");
                    }
                }

                if ((detail == null) || (!IsValidRequest(detail)))
                {
                    detail = null;
                    if (cmsSettings != null)
                    {
                        if (!string.IsNullOrEmpty(cmsSettings.PageNotFoundUrl))
                        {
                            ErrorHelper.LogException(new Exception($"Page Not Found: {virtualPath}"));

                            Response.Redirect(cmsSettings.PageNotFoundUrl);

                            /*FrameworkSettings.CurrentFrameworkBaseMedia = null;
                             *
                             * FrameworkSettings.CurrentFrameworkBaseMedia = FrameworkBaseMedia.GetInstanceByVirtualPath(cmsSettings.PageNotFoundUrl, true);
                             * detail = (MediaDetail)FrameworkSettings.CurrentFrameworkBaseMedia.CurrentMediaDetail;
                             *
                             * ErrorHelper.LogException(new Exception($"Page Not Found: {virtualPath}"));*/

                            //Response.StatusCode = 301;
                        }
                    }
                }

                if (detail != null)
                {
                    var draft = detail.GetLatestDraft();

                    if (draft != null && (draft.PublishDate - detail.PublishDate) > TimeSpan.FromSeconds(10) && draft.CanRender)
                    {
                        var returnObj = draft.PublishLive();

                        if (!returnObj.IsError)
                        {
                            detail.RemoveFromCache();
                            draft.RemoveFromCache();

                            FrameworkSettings.Current = FrameworkBaseMedia.GetInstanceByMediaDetail(draft);
                            detail = (MediaDetail)FrameworkSettings.Current.CurrentMediaDetail;
                        }
                    }

                    if (detail.RedirectToFirstChild)
                    {
                        var child = detail.ChildMediaDetails.FirstOrDefault();

                        if (child != null)
                        {
                            var redirectPath = child.AutoCalculatedVirtualPath;

                            if (!string.IsNullOrEmpty(queryString))
                            {
                                redirectPath = redirectPath + "?" + queryString;
                            }

                            HttpContext.Current.Response.Redirect(redirectPath);
                        }
                    }

                    viewPath = FrameworkSettings.Current.CurrentMediaDetail.Handler;

                    if ((viewPath == null) || (viewPath.Trim() == ""))
                    {
                        viewPath = MediaTypesMapper.GetByID(FrameworkSettings.Current.CurrentMediaDetail.MediaTypeID).MediaTypeHandler;
                    }

                    viewPath = URIHelper.ConvertAbsUrlToTilda(viewPath);

                    if (!string.IsNullOrEmpty(Request.QueryString["format"]))
                    {
                        FrontEndBasePage.HandleFormatQueryString(detail, Request.QueryString["format"], Request.QueryString["depth"]);
                    }

                    return(CreateInstanceFromVirtualPath(viewPath, typeof(BasePage)));
                }
            }

            return(new DefaultHttpHandler());
        }