Ejemplo n.º 1
0
        public void UpdateFieldsFromObject()
        {
            MediaDetailID.Text = selectedItem.ID.ToString();
            MediaID.Text       = selectedItem.MediaID.ToString();

            Handler.SetValue(selectedItem.Handler);
            MediaTypeID.Text      = selectedItem.MediaTypeID.ToString();
            MediaType.Text        = MediaTypesMapper.GetByID(selectedItem.MediaTypeID).Name.ToString();
            EnableCaching.Checked = selectedItem.EnableCaching;

            if (selectedItem.LastUpdatedByUserID != 0)
            {
                LastModifiedByUser.Text = UsersMapper.GetByID(selectedItem.LastUpdatedByUserID).UserName;
            }

            if (selectedItem.CreatedByUserID != 0)
            {
                CreatedByUser.Text = UsersMapper.GetByID(selectedItem.CreatedByUserID).UserName;
            }

            if (selectedItem.ID != 0)
            {
                OrderIndex.Text = MediasMapper.GetByMediaDetail(selectedItem).OrderIndex.ToString();
            }

            MasterPageSelector.SelectedValue = selectedItem.MasterPageID.ToString();
        }
Ejemplo n.º 2
0
        protected void MediaTypeChange_Click(object sender, System.EventArgs e)
        {
            var mewMediaTypeId = long.Parse(MediaTypes.SelectedValue);

            var newMediaType = MediaTypesMapper.GetDataModel().MediaTypes.FirstOrDefault(i => i.ID == mewMediaTypeId);

            if ((newMediaType != null) && (newMediaType.ID != selectedItem.MediaType.ID))
            {
                selectedItem.MediaTypeID         = newMediaType.ID;
                selectedItem.ShowInMenu          = newMediaType.ShowInMenu;
                selectedItem.ShowInSearchResults = newMediaType.ShowInSearchResults;

                foreach (var mediaTypeField in newMediaType.Fields)
                {
                    var foundField = selectedItem.Fields.SingleOrDefault(i => i.FieldCode == mediaTypeField.FieldCode);

                    if (foundField != null)
                    {
                        foundField.MediaTypeField = mediaTypeField;
                        continue;
                    }

                    var newField = new MediaDetailField();
                    newField.CopyFrom(mediaTypeField);
                    newField.UseMediaTypeFieldFrontEndLayout = true;

                    newField.DateCreated      = DateTime.Now;
                    newField.DateLastModified = DateTime.Now;

                    selectedItem.Fields.Add(newField);
                }

                if (selectedItem.UseMediaTypeLayouts)
                {
                    selectedItem.MainLayout     = newMediaType.MainLayout;
                    selectedItem.FeaturedLayout = newMediaType.FeaturedLayout;
                    selectedItem.SummaryLayout  = newMediaType.SummaryLayout;
                }

                foreach (var field in selectedItem.Fields)
                {
                    if (field.MediaTypeField != null && field.MediaTypeField.MediaType != newMediaType)
                    {
                        field.MediaTypeField = null;
                    }
                }

                var returnObj = MediaDetailsMapper.Update(selectedItem);

                if (returnObj.IsError)
                {
                    BasePage.DisplayErrorMessage("Error", returnObj.Error);
                }
                else
                {
                    var url = AdminBasePage.GetAdminUrl(selectedItem.MediaTypeID, selectedItem.MediaID);
                    Response.Redirect(url);
                }
            }
        }
        //public ViewMode Mode { get; set; }

        protected void AddItem_Click(object sender, EventArgs e)
        {
            var field = GetField();

            var media = MediasMapper.GetByID(field.MediaDetail.MediaID);

            var fieldAssociation = new FieldAssociation();

            fieldAssociation.MediaDetail = (MediaDetail)PagesMapper.CreateObject(MediaTypeID, MediasMapper.CreateObject(), media);
            fieldAssociation.MediaDetail.SectionTitle              = fieldAssociation.MediaDetail.ShortDescription = fieldAssociation.MediaDetail.MainContent = fieldAssociation.MediaDetail.LinkTitle;
            fieldAssociation.MediaDetail.PathToFile                = "/media/images/icons/File.jpg";
            fieldAssociation.MediaDetail.PublishDate               = DateTime.Now;
            fieldAssociation.MediaDetail.CreatedByUserID           = fieldAssociation.MediaDetail.LastUpdatedByUserID = FrameworkSettings.CurrentUser.ID;
            fieldAssociation.MediaDetail.CachedVirtualPath         = fieldAssociation.MediaDetail.CalculatedVirtualPath();
            fieldAssociation.MediaDetail.LanguageID                = AdminBasePage.CurrentLanguage.ID;
            fieldAssociation.MediaDetail.UseDefaultLanguageLayouts = false;

            var mediaType = MediaTypesMapper.GetByID(fieldAssociation.MediaDetail.MediaTypeID);

            if (mediaType != null)
            {
                fieldAssociation.MediaDetail.UseMediaTypeLayouts = mediaType.UseMediaTypeLayouts;
            }

            field.FieldAssociations.Add(fieldAssociation);
            var returnObj = BaseMapper.SaveDataModel();

            BindValues();
        }
Ejemplo n.º 4
0
        /*protected override void OnPreRender(EventArgs e)
         * {
         *  base.OnPreRender(e);
         *
         *  if (!IsPostBack)
         *      UpdateFieldsFromObject();
         * }*/

        private void UpdateSectionTitles()
        {
            string title        = "";
            string sectionTitle = "";

            if (selectedItem.ID == 0)
            {
                string       under      = "Root";
                IMediaDetail atleastOne = null;

                if (parentMediaItem != null)
                {
                    atleastOne = MediaDetailsMapper.GetAtleastOneByMedia(parentMediaItem, CurrentLanguage);
                }

                if ((parentMediaItem != null) && (atleastOne != null))
                {
                    under = atleastOne.LinkTitle;
                }

                sectionTitle = "Creating: <span>New Media of Type '" + MediaTypesMapper.GetByID(mediaTypeId).Name + "' Under '" + under + "' with Language '" + CurrentLanguage.Name + "'</span>";
                title        = StringHelper.StripHtmlTags(sectionTitle);
            }
            else
            {
                title        = "Editing: " + selectedItem.LinkTitle;
                sectionTitle = "Editing: <span>" + selectedItem.LinkTitle + "</span>";
            }

            this.Page.Title        = title;
            this.SectionTitle.Text = sectionTitle;
        }
Ejemplo n.º 5
0
        public void SetObject(IMediaDetail selectedItem)
        {
            this.selectedItem = selectedItem;

            if (selectedItem.ID != 0)
            {
                var allMediaTypes     = MediaTypesMapper.GetDataModel().MediaTypes.Where(i => i.IsActive);
                var allowedMediaTypes = new List <MediaType>();

                foreach (var mediaType in allMediaTypes)
                {
                    MediaTypeEnum mediaTypeEnum = MediaTypeEnum.Page;
                    Enum.TryParse(mediaType.Name, out mediaTypeEnum);

                    var tmpMediaDetail = MediaDetailsMapper.CreateObject(mediaTypeEnum);
                    if (tmpMediaDetail.GetType() == selectedItem.GetType())
                    {
                        allowedMediaTypes.Add(mediaType);
                    }
                }

                MediaTypes.DataSource     = allowedMediaTypes;
                MediaTypes.DataTextField  = "Name";
                MediaTypes.DataValueField = "ID";
                MediaTypes.DataBind();
            }

            //UpdateFieldsFromObject();
        }
Ejemplo n.º 6
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);
                }
            }
        }
Ejemplo n.º 7
0
        public void UpdateFieldsFromObject()
        {
            IMediaDetail item = (IMediaDetail)SelectedItem;

            if ((item.ID == 0) && (item.LinkTitle == null || item.LinkTitle == ""))
            {
                var mediaType    = MediaTypesMapper.GetByID(item.MediaTypeID);
                var createdItems = mediaType.MediaDetails.Where(i => !i.IsHistory && i.Media.ParentMediaID == item.Media.ParentMediaID && i.LanguageID == AdminBasePage.CurrentLanguage.ID).Select(i => i);

                var newIndex = createdItems.Count() + 1;

                item.LinkTitle = AdminBasePage.CurrentLanguage.DisplayName + " - " + mediaType.Name + " " + newIndex;
            }

            LinkTitle.Text = item.LinkTitle;

            var virtualPath = item.AutoCalculatedVirtualPath;

            /*if (LanguagesMapper.GetAllActive().Count() > 1)
             *  virtualPath = URIHelper.ConvertAbsUrlToTilda(URIHelper.ConvertToAbsUrl(virtualPath).Replace(URIHelper.BaseUrl, URIHelper.BaseUrlWithLanguage));*/

            VirtualPath.Text        = virtualPath;
            VirtualPath.NavigateUrl = URIHelper.ConvertToAbsUrl(virtualPath) + "?version=" + item.HistoryVersionNumber;

            UpdateTags();

            UpdateTabsFieldsFromObject();

            UpdateMediaFieldsFromObject();

            //SEOSettingsTab.UpdateFieldsFromObject();
            //PublishSettingsTab.UpdateFieldsFromObject();
        }
Ejemplo n.º 8
0
        protected void CopyFields_Click(object sender, EventArgs e)
        {
            var otherMediaType = MediaTypeSelector.GetSelectedMediaType();

            foreach (var otherMediaTypeField in otherMediaType.Fields)
            {
                if (!mediaType.Fields.Any(i => i.FieldCode == otherMediaTypeField.FieldCode))
                {
                    var mediaTypeField = new MediaTypeField();
                    mediaTypeField.CopyFrom(otherMediaTypeField);
                    mediaTypeField.DateCreated = mediaTypeField.DateLastModified = DateTime.Now;

                    mediaType.Fields.Add(mediaTypeField);

                    foreach (var mediaDetail in mediaType.MediaDetails)
                    {
                        var mediaDetailField = new MediaDetailField();
                        mediaDetailField.CopyFrom(mediaTypeField);

                        if (string.IsNullOrEmpty(mediaDetailField.UsageExample))
                        {
                            mediaDetailField.UsageExample = "{Field:" + mediaDetailField.FieldCode + "} OR {{Load:" + mediaDetail.MediaID + "}.Field:" + mediaDetailField.FieldCode + "}";
                        }

                        mediaDetailField.UseMediaTypeFieldFrontEndLayout = true;
                        mediaDetailField.UseMediaTypeFieldDescription    = true;

                        if (mediaDetailField.FrontEndSubmissions == null)
                        {
                            mediaDetailField.FrontEndSubmissions = "";
                        }

                        if (mediaDetailField.FieldSettings == null)
                        {
                            mediaDetailField.FieldSettings = "";
                        }

                        mediaDetailField.MediaTypeField = mediaTypeField;

                        mediaDetailField.DateCreated = mediaDetailField.DateLastModified = DateTime.Now;

                        mediaDetailField.OrderIndex = mediaDetail.Fields.Count;
                        mediaDetail.Fields.Add(mediaDetailField);
                    }
                }
            }

            var returnObj = MediaTypesMapper.Update(mediaType);

            if (!returnObj.IsError)
            {
                Bind();
            }
            else
            {
                BasePage.DisplayErrorMessage("Error", returnObj.Error);
            }
        }
Ejemplo n.º 9
0
        protected void Page_Init(object sender, EventArgs e)
        {
            if (Items == null)
            {
                Items = MediaTypesMapper.GetDataModel().MediaTypes.OrderBy(i => i.Name).ToList();
            }

            Bind();
        }
Ejemplo n.º 10
0
        private void ImportNewFields(IEnumerable <MediaTypeField> importFields)
        {
            foreach (var field in importFields)
            {
                if (!mediaType.Fields.Any(i => i.FieldCode == field.FieldCode))
                {
                    var mediaTypeField = new MediaTypeField();
                    mediaTypeField.CopyFrom(field);
                    mediaTypeField.DateCreated = mediaTypeField.DateLastModified = DateTime.Now;

                    mediaType.Fields.Add(mediaTypeField);

                    foreach (var mediaDetail in mediaType.MediaDetails)
                    {
                        var mediaDetailField = new MediaDetailField();
                        mediaDetailField.CopyFrom(mediaTypeField);

                        if (string.IsNullOrEmpty(mediaDetailField.UsageExample))
                        {
                            mediaDetailField.UsageExample = "{Field:" + mediaDetailField.FieldCode + "} OR {{Load:" + mediaDetail.MediaID + "}.Field:" + mediaDetailField.FieldCode + "}";
                        }

                        mediaDetailField.UseMediaTypeFieldFrontEndLayout = true;
                        mediaDetailField.UseMediaTypeFieldDescription    = true;

                        if (mediaDetailField.FrontEndSubmissions == null)
                        {
                            mediaDetailField.FrontEndSubmissions = "";
                        }

                        if (mediaDetailField.FieldSettings == null)
                        {
                            mediaDetailField.FieldSettings = "";
                        }

                        mediaDetailField.MediaTypeField = mediaTypeField;

                        mediaDetailField.DateCreated = mediaDetailField.DateLastModified = DateTime.Now;

                        mediaDetailField.OrderIndex = mediaDetail.Fields.Count;
                        mediaDetail.Fields.Add(mediaDetailField);
                    }
                }
            }

            var returnObj = MediaTypesMapper.Update(mediaType);

            if (!returnObj.IsError)
            {
                Bind();
            }
            else
            {
                BasePage.DisplayErrorMessage("Error", returnObj.Error);
            }
        }
Ejemplo n.º 11
0
        public void SetItem(IMediaDetail item)
        {
            this.selectedItem = item;
            var mediaTypeRoles = MediaTypesMapper.GetByID(item.MediaTypeID).GetRoles();

            if (mediaTypeRoles.Count() > 0)
            {
                RolePermissionsSelector.SetRoles(mediaTypeRoles);
            }
        }
Ejemplo n.º 12
0
        protected void PublishNow_OnClick(object sender, EventArgs e)
        {
            if (!CurrentUser.HasPermission(PermissionsEnum.Publish))
            {
                DisplayErrorMessage("Error publishing item", ErrorHelper.CreateError(new Exception("You do not have the appropriate permissions to publish items")));
                return;
            }

            selectedItem = BaseMapper.GetObjectFromContext((MediaDetail)selectedItem);

            if (selectedItem == null)
            {
                return;
            }

            var mediaType = MediaTypesMapper.GetByID(selectedItem.MediaTypeID);

            selectedItem.PublishDate = DateTime.Now;

            if (selectedItem.ExpiryDate != null)
            {
                selectedItem.ExpiryDate = null;
            }

            selectedItem.ShowInMenu          = mediaType.ShowInMenu;
            selectedItem.ShowInSearchResults = mediaType.ShowInSearchResults;
            selectedItem.EnableCaching       = mediaType.EnableCaching;

            Return returnObj = MediaDetailsMapper.Update(selectedItem);

            if (returnObj.IsError)
            {
                DisplayErrorMessage("Error Publishing Item", returnObj.Error);
            }
            else
            {
                DisplaySuccessMessage("Successfully Published Item");

                var mediaId = (selectedItem.Media.ParentMediaID != null) ? selectedItem.Media.ParentMediaID : selectedItem.MediaID;

                ExecuteRawJS("RefreshSiteTreeNodeById(" + mediaId + "); ReloadPreviewPanel();");

                UpdateFieldsFromObject();

                PublishNow.Visible = false;
                ContextHelper.Clear(ContextType.Cache);
                FileCacheHelper.ClearAllCache();
            }

            UpdateFieldsFromObject();

            OnPublishExecuteCode();
        }
Ejemplo n.º 13
0
        protected void Page_init(object sender, EventArgs e)
        {
            long id;

            if (long.TryParse(Request["id"], out id))
            {
                selectedItem = MediaTypesMapper.GetByID(id);

                if (!IsPostBack)
                {
                    UpdateFieldsFromObject();
                }
            }

            MediaTypeFieldsEditor.SetItems(selectedItem);

            this.Page.Title = this.SectionTitle.Text = GetSectionTitle();
        }
Ejemplo n.º 14
0
        protected void Save_OnClick(object sender, EventArgs e)
        {
            if (selectedItem == null)
            {
                selectedItem = MediaTypesMapper.CreateObject();
            }
            else
            {
                selectedItem = BaseMapper.GetObjectFromContext <MediaType>(selectedItem);
            }

            UpdateObjectFromFields();

            Return returnObj = selectedItem.Validate();

            if (!returnObj.IsError)
            {
                if (selectedItem.ID == 0)
                {
                    returnObj = MediaTypesMapper.Insert(selectedItem);
                }
                else
                {
                    returnObj = MediaTypesMapper.Update(selectedItem);
                }
            }

            if (returnObj.IsError)
            {
                DisplayErrorMessage("Error Saving Item", returnObj.Error);
            }
            else
            {
                /*var mediaDetails = selectedItem.MediaDetails.Where(i => i.HistoryForMediaDetail == null);
                 *
                 * foreach (var mediaDetail in mediaDetails)
                 * {
                 *  mediaDetail.RemoveFromCache();
                 * }*/

                DisplaySuccessMessage("Successfully Saved Item");
            }
        }
Ejemplo n.º 15
0
        protected void Delete_Click(object sender, EventArgs e)
        {
            var field = GetDataItemFromSender((Control)sender);

            if (field != null && field.ID != 0)
            {
                //TODO: Only un-comment for testing
                var mediaDetailFields = field.MediaDetailFields.ToList();

                foreach (var mediaDetailField in mediaDetailFields)
                {
                    var fieldAssociations = mediaDetailField.FieldAssociations.ToList();
                    foreach (var item in fieldAssociations)
                    {
                        if (!item.MediaDetail.MediaType.ShowInSiteTree)
                        {
                            var media = item.MediaDetail.Media;

                            MediaDetailsMapper.ClearObjectRelations(item.MediaDetail);
                            BaseMapper.DeleteObjectFromContext(item.MediaDetail);
                        }
                    }

                    BaseMapper.DeleteObjectFromContext(mediaDetailField);
                }
                // End of TODO

                BaseMapper.DeleteObjectFromContext(field);

                var returnObj = MediaTypesMapper.Update(mediaType);

                if (!returnObj.IsError)
                {
                    UpdatedFieldsFromObject(new MediaTypeField());
                    Bind();
                }
                else
                {
                    BasePage.DisplayErrorMessage("Error", returnObj.Error);
                }
            }
        }
Ejemplo n.º 16
0
        public string DeleteItemPermanently(long id)
        {
            MediaType item = BaseMapper.GetObjectFromContext(MediaTypesMapper.GetByID(id));

            if (item != null)
            {
                Return returnObj = MediaTypesMapper.DeletePermanently(item);

                if (returnObj.IsError)
                {
                    return(jGrowlHelper.GenerateCode(new jGrowlMessage("Error", "Error deleting item permanently", jGrowlMessage.jGrowlMessageType.Error, returnObj.Error), true));
                }
                else
                {
                    return(jGrowlHelper.GenerateCode(new jGrowlMessage("Success", "Item was successfully deleted permanently", jGrowlMessage.jGrowlMessageType.Success), false));
                }
            }

            return("");
        }
Ejemplo n.º 17
0
        protected void Page_Init(object sender, EventArgs e)
        {
            long id;
            long parentId;

            long.TryParse(Request["historyVersion"], out historyVersion);
            long.TryParse(Request["mediaTypeId"], out mediaTypeId);

            if (long.TryParse(Request["selectedMediaId"], out id))
            {
                selectedMediaItem = MediasMapper.GetByID(id);
                SelectedMedia     = selectedMediaItem;

                if (selectedMediaItem != null)
                {
                    selectedItem = MediaDetailsMapper.GetByMedia(selectedMediaItem, CurrentLanguage);

                    if (historyVersion > 0)
                    {
                        selectedItem       = BaseMapper.GetObjectFromContext((MediaDetail)selectedItem);
                        historyVersionItem = BaseMapper.GetObjectFromContext((MediaDetail)MediaDetailsMapper.GetByMedia(selectedMediaItem, CurrentLanguage, historyVersion));
                    }

                    if ((selectedItem != null) && (historyVersionItem != null))
                    {
                        tmpSelectedItem = BaseMapper.GetObjectFromContext((MediaDetail)selectedItem);
                        selectedItem    = historyVersionItem;
                    }
                }
            }

            if (long.TryParse(Request["parentMediaId"], out parentId))
            {
                parentMediaItem = MediasMapper.GetByID(parentId);
            }

            if (selectedItem == null)
            {
                if (parentMediaItem != null)
                {
                    SelectedMedia = parentMediaItem;
                }

                /*if (parentMediaItem == null)
                 *  return;*/

                selectedItem = MediaDetailsMapper.CreateObject(mediaTypeId, selectedMediaItem, parentMediaItem);
            }

            Return canAccessReturnObj = BaseMapper.GenerateReturn();

            if (selectedItem.ID != 0)
            {
                canAccessReturnObj = MediaDetailsMapper.CanAccessMediaDetail(selectedItem, CurrentUser);
                if (canAccessReturnObj.IsError)
                {
                    DisplayErrorMessage("Cannot edit item", canAccessReturnObj.Error);

                    CanAccessItem = canAccessReturnObj;

                    return;
                }
                else
                {
                    KeyValuePair <IMediaDetail, User> checkedOutItem = IsCheckedOut(selectedItem);

                    if (checkedOutItem.Key == null)
                    {
                        CheckOut(selectedItem);
                    }
                    else
                    {
                        if (checkedOutItem.Value.ID != CurrentUser.ID)
                        {
                            Return returnObj = BaseMapper.GenerateReturn("Cannot edit item", "The item has been checked out by user: ( " + checkedOutItem.Value.UserName + " )");

                            CanAccessItem = returnObj;

                            DisplayErrorMessage("Error", returnObj.Error);

                            return;
                        }
                    }
                }
            }

            SelectedMediaDetail = selectedItem;
            SelectedMedia       = selectedMediaItem;

            if (selectedMediaItem == null)
            {
                SelectedMedia = parentMediaItem;
            }

            if (selectedItem.ID == 0)
            {
                Save.Text           = "Create";
                SaveAndPublish.Text = "Create And Publish";

                LoadLatestDraft.Visible = false;
                CreateDraft.Visible     = false;

                var mediaType = MediaTypesMapper.GetByID(selectedItem.MediaTypeID);

                if (mediaType == null)
                {
                    return;
                }

                selectedItem.MainLayout     = mediaType.MainLayout;
                selectedItem.SummaryLayout  = mediaType.SummaryLayout;
                selectedItem.FeaturedLayout = mediaType.FeaturedLayout;

                selectedItem.UseMediaTypeLayouts = mediaType.UseMediaTypeLayouts;

                var liveMediaDetail = selectedItem.Media?.GetLiveMediaDetail();

                if (liveMediaDetail != null)
                {
                    selectedItem.CopyFrom(liveMediaDetail);

                    var fieldsNotInMediaType = liveMediaDetail.Fields.Where(i => i.MediaTypeFieldID == null);

                    if (fieldsNotInMediaType != null)
                    {
                        foreach (var field in fieldsNotInMediaType)
                        {
                            var newField = new MediaDetailField();
                            newField.CopyFrom(field);

                            if (field.FieldAssociations.Count > 0)
                            {
                                newField.FieldValue = "";
                            }
                            else
                            {
                                newField.FieldValue = field.FieldValue;
                            }

                            newField.DateCreated      = DateTime.Now;
                            newField.DateLastModified = DateTime.Now;

                            selectedItem.Fields.Add(newField);
                        }
                    }

                    var fieldsThatCanBeCopied = liveMediaDetail.Fields.Where(i => !i.FieldAssociations.Any());

                    foreach (var field in fieldsThatCanBeCopied)
                    {
                        var foundField = selectedItem.Fields.FirstOrDefault(i => i.FieldCode == field.FieldCode);

                        if (foundField != null)
                        {
                            foundField.CopyFrom(field);
                        }
                    }
                }
            }
            else
            {
                Save.Text           = "Save Page";
                SaveAndPublish.Text = "Save And Publish";
            }

            if ((historyVersion > 0) && (historyVersionItem != null) && (!historyVersionItem.IsDraft))
            {
                //SavePanel.Visible = false;
            }
            else
            {
                var draftItems = selectedItem.History.Where(i => i.IsDraft);

                if (draftItems.Count() > 0)
                {
                    LoadLatestDraft.Visible = true;
                    CreateDraft.Visible     = false;
                }

                SaveAndPublish.Visible = true;
                SavePanel.Visible      = true;

                HistoryPanel.Visible = false;
            }

            if (historyVersion > 0)
            {
                SavePanel.Visible = true;

                if (!selectedItem.IsDraft)
                {
                    Save.Visible = false;
                }

                CreateDraft.Visible = false;
                PublishNow.Visible  = false;
                PublishLive.Visible = true;

                HistoryPanel.Visible      = true;
                HistoryVersionNumber.Text = historyVersion.ToString();
            }

            if (CurrentUser.IsInRole(RoleEnum.Developer))
            {
                EditMediaType.NavigateUrl = "~/Admin/Views/PageHandlers/MediaTypes/Detail.aspx?id=" + SelectedMediaDetail.MediaTypeID;
                EditMediaType.Visible     = true;
            }

            Panel.SetObject(SelectedMediaDetail);

            if (Request.QueryString["masterFilePath"] != null)
            {
                PreviewPanel.Visible             = false;
                RemovePreviewPanelScript.Visible = true;
            }
            else
            {
                PreviewPanel.Visible             = true;
                RemovePreviewPanelScript.Visible = false;
            }

            UpdateSectionTitles();
        }
Ejemplo n.º 18
0
 protected void Page_Init(object sender, EventArgs e)
 {
     Bind(MediaTypesMapper.GetAllActive());
 }
Ejemplo n.º 19
0
        protected void Update_Click(object sender, EventArgs e)
        {
            if (mediaType.ID == 0)
            {
                BasePage.DisplayErrorMessage("You can only add fields once you have created the page");
                return;
            }

            if (FieldCode.Text == "")
            {
                BasePage.DisplayErrorMessage("'FieldCode' cannot be blank");
                return;
            }

            var fieldId = long.Parse(FieldID.Value);

            if (fieldId == 0)
            {
                var mediaTypeField = new MediaTypeField();
                UpdatedObjectFromFields(mediaTypeField);

                mediaType.Fields.Add(mediaTypeField);

                foreach (var mediaDetail in mediaType.MediaDetails)
                {
                    var mediaDetailField = new MediaDetailField();
                    mediaDetailField.CopyFrom(mediaTypeField);

                    if (string.IsNullOrEmpty(mediaDetailField.UsageExample))
                    {
                        mediaDetailField.UsageExample = "{Field:" + mediaDetailField.FieldCode + "} OR {{Load:" + mediaDetail.MediaID + "}.Field:" + mediaDetailField.FieldCode + "}";
                    }

                    mediaDetailField.UseMediaTypeFieldFrontEndLayout = true;
                    mediaDetailField.UseMediaTypeFieldDescription    = true;

                    if (mediaDetailField.FrontEndSubmissions == null)
                    {
                        mediaDetailField.FrontEndSubmissions = "";
                    }

                    if (mediaDetailField.FieldSettings == null)
                    {
                        mediaDetailField.FieldSettings = "";
                    }

                    mediaDetailField.MediaTypeField = mediaTypeField;

                    mediaDetailField.DateCreated = mediaDetailField.DateLastModified = DateTime.Now;

                    mediaDetailField.OrderIndex = mediaDetail.Fields.Count;
                    mediaDetail.Fields.Add(mediaDetailField);
                }
            }
            else
            {
                var mediaTypeField = mediaType.Fields.SingleOrDefault(i => i.ID == fieldId);
                var oldFieldCode   = mediaTypeField.FieldCode;

                UpdatedObjectFromFields(mediaTypeField);

                foreach (var mediaDetailField in mediaTypeField.MediaDetailFields)
                {
                    var mediaDetailFieldValue = mediaDetailField.FieldValue;
                    mediaDetailField.CopyFrom(mediaTypeField);

                    if (string.IsNullOrEmpty(mediaDetailField.UsageExample))
                    {
                        mediaDetailField.UsageExample = "{Field:" + mediaDetailField.FieldCode + "} OR {{Load:" + mediaDetailField.MediaDetail.MediaID + "}.Field:" + mediaDetailField.FieldCode + "}";
                    }

                    if (mediaDetailField.UseMediaTypeFieldDescription)
                    {
                        mediaDetailField.FieldDescription = mediaTypeField.FieldDescription;
                    }

                    if (mediaDetailField.UseMediaTypeFieldFrontEndLayout)
                    {
                        mediaDetailField.FrontEndLayout = mediaTypeField.FrontEndLayout;
                    }

                    if (string.IsNullOrEmpty(mediaDetailFieldValue))
                    {
                        mediaDetailField.FieldValue = mediaTypeField.FieldValue;
                    }
                    else
                    {
                        mediaDetailField.FieldValue = mediaDetailFieldValue;
                    }


                    mediaDetailField.DateLastModified = DateTime.Now;
                }
            }

            var returnObj = MediaTypesMapper.Update(mediaType);

            if (!returnObj.IsError)
            {
                Bind();

                /*var liveMediaDetails = mediaType.MediaDetails.Where(i => i.HistoryVersionNumber == 0);
                 *
                 * foreach (var item in liveMediaDetails)
                 * {
                 *  item.RemoveFromCache();
                 * }*/
            }
            else
            {
                BasePage.DisplayErrorMessage("Error", returnObj.Error);
            }
        }
Ejemplo n.º 20
0
 public MediaType GetSelectedMediaType()
 {
     return(MediaTypesMapper.GetByID(long.Parse(MediaTypes.SelectedValue)));
 }
Ejemplo n.º 21
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());
        }