public async Task <ActionResult> AddNewPage_Partial(AddNewPageModel model) { if (!ModelState.IsValid) { return(PartialView(model)); } PageDefinition basePage = null; if (model.CopyPage) { basePage = await PageDefinition.LoadAsync(model.CurrentPageGuid); } PageDefinition.NewPageInfo newPage = await PageDefinition.CreateNewPageAsync(model.Title, model.Description, model.Url, basePage, model.CopyModules); PageDefinition page = newPage.Page; if (page == null) { ModelState.AddModelError(nameof(model.Url), newPage.Message); return(PartialView(model)); } await page.SaveAsync(); return(FormProcessed(model, this.__ResStr("okNewPage", "New page created"), NextPage: page.EvaluatedCanonicalUrl)); }
public async Task <ActionResult> AddNewModule_Partial(AddNewModuleModel model) { PageDefinition page = await PageDefinition.LoadAsync(model.CurrentPageGuid); if (page == null) { throw new Error("Can't edit this page"); } model.AddData(page); if (!ModelState.IsValid) { return(PartialView(model)); } ModuleDefinition module = ModuleDefinition.CreateNewDesignedModule(model.SelectedModule, model.ModuleName, model.ModuleTitle); if (!module.IsModuleUnique) { module.ModuleGuid = Guid.NewGuid(); } page.AddModule(model.SelectedPane, module, model.ModuleLocation == Location.Top); await page.SaveAsync(); return(Reload(model, PopupText: this.__ResStr("okNew", "New module added"))); }
public async Task <ActionResult> PageEdit_Partial(EditModel model) { PageDefinition page = await PageDefinition.LoadAsync(model.PageGuid); if (page == null) { throw new Error(this.__ResStr("alreadyDeleted", "This page has been removed and can no longer be updated.")); } model.UpdateData(page); ObjectSupport.CopyData(page, model.Page, ReadOnly: true); // update read only properties in model in case there is an error model.Page.FavIcon_Data = page.FavIcon_Data; // copy favicon if (!ModelState.IsValid) { return(PartialView(model)); } page = model.GetData(page); // merge new data into original model.SetData(page); // and all the data back into model for final display await page.SaveAsync(); // this handles changing the Url automatically MenuList.ClearCachedMenus(); // page changes may affect all menus so clear the menu cache (this only clears current session) // if we're in a popup and the parent page is the page we're editing, then force a reload //$$$$ rename with querystring doesn't work OnPopupCloseEnum popupClose = OnPopupCloseEnum.ReloadModule; if (PageDefinition.IsSamePage(Manager.QueryReturnToUrl.Url, model.Page.Url)) { popupClose = OnPopupCloseEnum.ReloadParentPage; } return(FormProcessed(model, this.__ResStr("okSaved", "Page settings saved"), OnPopupClose: popupClose)); }
public async Task <ActionResult> SetUser(Guid guid) { using (PageDefinitionDataProvider pageDP = new PageDefinitionDataProvider()) { int adminRole = Resource.ResourceAccess.GetAdministratorRoleId(); int userRole = Resource.ResourceAccess.GetUserRoleId(); PageDefinition page = await PageDefinition.LoadAsync(guid); if (page == null) { throw new InternalError($"Page with Guid {0} not found", guid); } page.AllowedRoles = new SerializableList <PageDefinition.AllowedRole>(); page.AllowedUsers = new SerializableList <PageDefinition.AllowedUser>(); page.AllowedRoles.Add(new PageDefinition.AllowedRole { RoleId = userRole, View = PageDefinition.AllowedEnum.Yes }); foreach (PageDefinition.ModuleEntry modEntry in page.ModuleDefinitions) { ModuleDefinition module = await modEntry.GetModuleAsync(); if (module != null) { module.AllowedRoles = new SerializableList <ModuleDefinition.AllowedRole>(); module.AllowedUsers = new SerializableList <ModuleDefinition.AllowedUser>(); module.AllowedRoles.Add(new ModuleDefinition.AllowedRole { RoleId = userRole, View = ModuleDefinition.AllowedEnum.Yes }); } } await page.SaveAsync(); } return(Reload(null, Reload: ReloadEnum.ModuleParts)); }
public async Task <ActionResult> UpdateAdminAndEditorAuthorization() { using (PageDefinitionDataProvider pageDP = new PageDefinitionDataProvider()) { int adminRole = Resource.ResourceAccess.GetAdministratorRoleId(); int editorRole = Resource.ResourceAccess.GetEditorRoleId(); DataProviderGetRecords <PageDefinition> pages = await pageDP.GetItemsAsync(0, 0, null, null); foreach (PageDefinition genericPage in pages.Data) { PageDefinition page = await PageDefinition.LoadAsync(genericPage.PageGuid); if (page != null) { PageDefinition.AllowedRole role; while ((role = PageDefinition.AllowedRole.Find(page.AllowedRoles, adminRole)) != null) { page.AllowedRoles.Remove(role); } page.AllowedRoles.Add(new PageDefinition.AllowedRole { RoleId = adminRole, View = PageDefinition.AllowedEnum.Yes, Edit = PageDefinition.AllowedEnum.Yes, Remove = PageDefinition.AllowedEnum.Yes, }); while ((role = PageDefinition.AllowedRole.Find(page.AllowedRoles, editorRole)) != null) { page.AllowedRoles.Remove(role); } page.AllowedRoles.Add(new PageDefinition.AllowedRole { RoleId = editorRole, View = PageDefinition.AllowedEnum.Yes, Edit = PageDefinition.AllowedEnum.Yes, }); await page.SaveAsync(); } } } return(Reload(null, Reload: ReloadEnum.ModuleParts)); }
public async Task <ActionResult> ExportPage(Guid pageGuid, long cookieToReturn) { PageDefinition page = await PageDefinition.LoadAsync(pageGuid); YetaWFZipFile zipFile = await page.ExportAsync(); return(new ZippedFileResult(zipFile, cookieToReturn)); }
private async Task <PageDefinition> LoadPageAsync(Guid pageGuid) { PageDefinition page = await PageDefinition.LoadAsync(pageGuid); if (page == null) { throw new Error(this.__ResStr("pageNotFound", "Page {0} doesn't exist"), pageGuid.ToString()); } return(page); }
/// <summary> /// Called by the framework when the component needs to be rendered as HTML. /// </summary> /// <param name="model">The model being rendered by the component.</param> /// <returns>The component rendered as HTML.</returns> public async Task <string> RenderAsync(Guid?model) { HtmlBuilder hb = new HtmlBuilder(); // dropdown List <SelectionItem <string> > list; list = ( from p in await PageDefinition.GetDesignedPagesAsync() orderby p.Url select new SelectionItem <string> { Text = p.Url, Value = p.PageGuid.ToString(), }).ToList <SelectionItem <string> >(); list.Insert(0, new SelectionItem <string> { Text = __ResStr("select", "(select)"), Value = null }); string ddList = await DropDownListComponent.RenderDropDownListAsync(this, (model ?? Guid.Empty).ToString(), list, null); // link YTagBuilder tag = new YTagBuilder("a"); PageDefinition page = null; if (model != null) { page = await PageDefinition.LoadAsync((Guid)model); } tag.MergeAttribute("href", (page != null ? page.EvaluatedCanonicalUrl : "")); tag.MergeAttribute("target", "_blank"); tag.MergeAttribute("rel", "nofollow noopener noreferrer"); tag.Attributes.Add(Basics.CssTooltip, __ResStr("linkTT", "Click to preview the page in a new window - not all pages can be displayed correctly and may require additional parameters")); tag.InnerHtml = tag.InnerHtml + ImageHTML.BuildKnownIcon("#PagePreview", sprites: Info.PredefSpriteIcons); string linkTag = tag.ToString(YTagRenderMode.Normal); hb.Append($@" <div id='{DivId}' class='yt_pageselection t_edit'> <div class='t_select'> {ddList.ToString()} </div> <div class='t_link'> {linkTag} </div> <div class='t_description'> </div> </div>"); Manager.ScriptManager.AddLast($@"new YetaWF_ComponentsHTML.PageSelectionEditComponent('{DivId}');"); return(hb.ToString()); }
public async Task <ActionResult> RemovePage(Guid pageGuid) { PageDefinition page = page = await PageDefinition.LoadAsync(pageGuid); if (page == null) { throw new InternalError("Page {0} does not exist", pageGuid); } if (!page.IsAuthorized_Remove()) { return(NotAuthorized()); } await PageDefinition.RemovePageDefinitionAsync(pageGuid); return(Redirect((string)null)); }
public async Task <ModuleAction> GetAction_ExportPageAsync(Guid?pageGuid = null) { Guid guid; PageDefinition page; if (pageGuid == null) { page = Manager.CurrentPage; if (page == null) { return(null); } guid = page.PageGuid; } else { guid = (Guid)pageGuid; page = await PageDefinition.LoadAsync(guid); } if (page == null) { return(null); } if (!await Resource.ResourceAccess.IsResourceAuthorizedAsync(CoreInfo.Resource_PageExport)) { return(null); } return(new ModuleAction(this) { Url = Utility.UrlFor(typeof(PageControlModuleController), nameof(PageControlModuleController.ExportPage)), QueryArgs = new { PageGuid = guid }, QueryArgsDict = new QueryHelper(new QueryDictionary { { Basics.ModuleGuid, this.ModuleGuid }, // the module authorizing this }), Image = await CustomIconAsync("ExportPage.png"), Name = "ExportPage", LinkText = this.__ResStr("modExportLink", "Export"), MenuText = this.__ResStr("modExportMenu", "Export Page"), Tooltip = this.__ResStr("modExportTT", "Export the page and modules by creating an importable ZIP file (using Control Panel, Import Page)"), Legend = this.__ResStr("modExportLegend", "Exports the page and modules by creating an importable ZIP file (using Control Panel, Import Page)"), Location = ModuleAction.ActionLocationEnum.NoAuto | ModuleAction.ActionLocationEnum.MainMenu | ModuleAction.ActionLocationEnum.ModuleLinks | ModuleAction.ActionLocationEnum.ModuleMenu, Mode = ModuleAction.ActionModeEnum.Any, CookieAsDoneSignal = true, Style = ModuleAction.ActionStyleEnum.Normal, }); }
public async Task <ModuleAction> GetAction_RemoveAsync(Guid?pageGuid = null) { Guid guid; PageDefinition page; if (pageGuid == null) { page = Manager.CurrentPage; if (page == null) { return(null); } guid = page.PageGuid; } else { guid = (Guid)pageGuid; page = await PageDefinition.LoadAsync(guid); } if (page == null) { return(null); } if (!page.IsAuthorized_Remove()) { return(null); } return(new ModuleAction(this) { Url = Utility.UrlFor(typeof(PageEditModuleController), "RemovePage"), QueryArgs = new { PageGuid = guid }, Image = "#Remove", Name = "RemovePage", LinkText = this.__ResStr("delLink", "Remove Current Page"), MenuText = this.__ResStr("delText", "Remove Current Page"), Tooltip = this.__ResStr("delTooltip", "Remove the current page"), Legend = this.__ResStr("delLegend", "Removes the current page"), Style = ModuleAction.ActionStyleEnum.Post, Category = ModuleAction.ActionCategoryEnum.Delete, Location = ModuleAction.ActionLocationEnum.ModuleLinks | ModuleAction.ActionLocationEnum.ModuleMenu, Mode = ModuleAction.ActionModeEnum.Any, ConfirmationText = this.__ResStr("delConfirm", "Are you ABSOLUTELY sure you want to remove the currently displayed page? This action cannot be undone."), NeedsModuleContext = true, }); }
public async Task <ActionResult> AddExistingModule_Partial(AddExistingModel model) { PageDefinition page = await PageDefinition.LoadAsync(model.CurrentPageGuid); if (page == null) { throw new Error("Can't edit this page"); } model.AddData(page); if (!ModelState.IsValid) { return(PartialView(model)); } ModuleDefinition module = await ModuleDefinition.LoadAsync(model.ExistingModule); page.AddModule(model.ExistingModulePane, module, model.ModuleLocation == Location.Top); await page.SaveAsync(); return(Reload(model, PopupText: this.__ResStr("okExisting", "Module added"))); }
public async Task <ActionResult> PageEdit(Guid pageGuid) { if (pageGuid == Guid.Empty) { throw new InternalError("No pageGuid provided"); } PageDefinition page = await PageDefinition.LoadAsync(pageGuid); if (page == null) { throw new Error(this.__ResStr("notFound", "Page {0} doesn't exist", pageGuid)); } EditModel model = new EditModel() { PageGuid = pageGuid }; model.SetData(page); model.UpdateData(page); Module.Title = this.__ResStr("modEditTitle", "Page {0}", page.Url); return(View(model)); }
public async Task <ActionResult> PageControl() { if (Manager.IsInPopup) { return(new EmptyResult()); } if (Manager.CurrentPage == null || Manager.CurrentPage.Temporary) { return(new EmptyResult()); } #if DEBUG // allow in debug mode without checking unless marked deployed if (YetaWFManager.Deployed && !Manager.CurrentPage.IsAuthorized_Edit()) { return(new EmptyResult()); } #else if (!Manager.CurrentPage.IsAuthorized_Edit()) { return(new EmptyResult()); } #endif Guid pageGuid = Guid.Empty; if (pageGuid == Guid.Empty) { if (Manager.CurrentPage == null) { pageGuid = new Guid(); // we're not on a designed page } else { pageGuid = Manager.CurrentPage.PageGuid; } } PageDefinition page = await PageDefinition.LoadAsync(pageGuid); bool editAuthorized = false; if (page.IsAuthorized_Edit()) { editAuthorized = true; } PageControlModel model = new PageControlModel() { EditAuthorized = editAuthorized, AddNewPageModel = new AddNewPageModel() { CurrentPageGuid = Manager.CurrentPage.PageGuid, }, AddNewModel = new AddNewModuleModel() { CurrentPageGuid = Manager.CurrentPage.PageGuid, }, AddExistingModel = new AddExistingModel() { CurrentPageGuid = Manager.CurrentPage.PageGuid, }, ImportPageModel = new ImportPageModel(), ImportModuleModel = new ImportModuleModel() { CurrentPageGuid = Manager.CurrentPage.PageGuid, }, SkinSelectionModel = new SkinSelectionModel { BootstrapSkin = Manager.CurrentSite.BootstrapSkin, jQueryUISkin = Manager.CurrentSite.jQueryUISkin, KendoUISkin = Manager.CurrentSite.KendoUISkin, BootstrapSkinDescription = (!Manager.SkinInfo.UsingBootstrap || !Manager.SkinInfo.UseDefaultBootstrap) ? this.__ResStr("noBootswatch", "The current page skin does not support selecting a default Bootstrap skin. The skin does not support Bootswatch, which is required for skin selection.") : null, }, LoginSiteSelectionModel = new LoginSiteSelectionModel(), }; PageEditModule modEdit = new PageEditModule(); model.Actions = new List <ModuleAction>(); model.Actions.New(await modEdit.GetAction_EditAsync(null)); model.Actions.New(await Module.GetAction_ExportPageAsync(null)); model.Actions.New(await modEdit.GetAction_RemoveAsync(null)); model.Actions.New(Module.GetAction_SwitchToView()); model.Actions.New(Module.GetAction_SwitchToEdit()); model.Actions.New(await Module.GetAction_W3CValidationAsync()); model.Actions.New(await Module.GetAction_RestartSite()); model.Actions.New(Module.GetAction_ClearJsCssCache()); model.AddNewModel.AddData(page); model.AddExistingModel.AddData(page); model.ImportPageModel.AddData(page, Module); model.ImportModuleModel.AddData(page, Module); await model.LoginSiteSelectionModel.AddDataAsync(); return(View(model)); }
/// <summary> /// Creates a site map for the current site. /// </summary> public async Task CreateAsync(bool slow = false) { string file = GetTempFile(); await FileSystem.FileSystemProvider.DeleteFileAsync(file); // header await FileSystem.FileSystemProvider.AppendAllTextAsync(file, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n" + "<urlset xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns =\"http://www.sitemaps.org/schemas/sitemap/0.9\" >\r\n" ); // Dynamic Urls in types DynamicUrlsImpl dynamicUrls = new DynamicUrlsImpl(); List <Type> types = dynamicUrls.GetDynamicUrlTypes(); foreach (Type type in types) { ISiteMapDynamicUrls iSiteMap = Activator.CreateInstance(type) as ISiteMapDynamicUrls; if (iSiteMap != null) { await iSiteMap.FindDynamicUrlsAsync(AddSiteMapPageAsync, ValidForSiteMap); } } // search all designed modules that have dynamic urls foreach (DesignedModule desMod in await DesignedModules.LoadDesignedModulesAsync()) { ModuleDefinition mod = await ModuleDefinition.LoadAsync(desMod.ModuleGuid, AllowNone : true); if (mod != null) { ISiteMapDynamicUrls iSiteMap = mod as ISiteMapDynamicUrls; if (iSiteMap != null) { await iSiteMap.FindDynamicUrlsAsync(AddSiteMapPageAsync, ValidForSiteMap); } } } // Designed pages List <Guid> pages = await PageDefinition.GetDesignedGuidsAsync(); foreach (Guid pageGuid in pages) { PageDefinition page = await PageDefinition.LoadAsync(pageGuid); if (page == null) { continue; } if (!PagesFound.Contains(page.PageGuid)) // don't include same again (this could be a page that generates dynamic Urls) { await AddUrlAsync(file, page, page.EvaluatedCanonicalUrl, page.Updated, page.SiteMapPriority, page.ChangeFrequency); } } // end await FileSystem.FileSystemProvider.AppendAllTextAsync(file, "</urlset>\r\n" ); string finalFile = GetFile(); await FileSystem.FileSystemProvider.DeleteFileAsync(finalFile); await FileSystem.FileSystemProvider.MoveFileAsync(file, finalFile); if (Manager.CurrentSite.DefaultSiteMap) { await FileSystem.FileSystemProvider.CopyFileAsync(finalFile, Path.Combine(YetaWFManager.RootFolder, "sitemap.xml")); } }
public async Task SearchSiteAsync(bool slow) { SearchConfigData searchConfig = await SearchConfigDataProvider.GetConfigAsync(); DateTime searchStarted = DateTime.UtcNow; // once we have all new keywords, delete all keywords that were added before this date/time using (SearchDataProvider searchDP = new SearchDataProvider()) { // Search all generated pages (unique modules or classes, like data providers) DynamicUrlsImpl dynamicUrls = new DynamicUrlsImpl(); List <Type> types = dynamicUrls.GetDynamicUrlTypes(); // search types that generate dynamic urls foreach (Type type in types) { #if DEBUG // if (type.Name != "FileDocumentDisplayModule") continue;//used for debugging #endif ISearchDynamicUrls iSearch = Activator.CreateInstance(type) as ISearchDynamicUrls; if (iSearch != null) { try { SearchWords searchWords = new SearchWords(searchConfig, searchDP, searchStarted); await iSearch.KeywordsForDynamicUrlsAsync(searchWords); if (slow) { Thread.Sleep(500);// delay a bit (slow can only be used by scheduler items) } } catch (Exception exc) { Logging.AddErrorLog("KeywordsForDynamicUrls failed for {0}", type.FullName, exc); } } } // search all designed modules that have dynamic urls foreach (DesignedModule desMod in await DesignedModules.LoadDesignedModulesAsync()) { try { ModuleDefinition mod = await ModuleDefinition.LoadAsync(desMod.ModuleGuid, AllowNone : true); if (mod != null && types.Contains(mod.GetType()) && mod.WantSearch) { ISearchDynamicUrls iSearch = mod as ISearchDynamicUrls; if (iSearch != null) { SearchWords searchWords = new SearchWords(searchConfig, searchDP, searchStarted); await iSearch.KeywordsForDynamicUrlsAsync(searchWords); if (slow) { Thread.Sleep(500);// delay a bit (slow can only be used by scheduler items) } } } } catch (Exception exc) { Logging.AddErrorLog("KeywordsForDynamicUrls failed for module {0}", desMod.ModuleGuid, exc); } } // Search all designed pages and extract keywords List <Guid> pages = await PageDefinition.GetDesignedGuidsAsync(); foreach (Guid pageGuid in pages) { PageDefinition page = await PageDefinition.LoadAsync(pageGuid); if (page != null) { SearchWords searchWords = new SearchWords(searchConfig, searchDP, searchStarted); await SearchPageAsync(searchWords, page); if (slow) { Thread.Sleep(500);// delay a bit (slow can only be used by scheduler items) } } } // Remove old keywords await searchDP.RemoveOldItemsAsync(searchStarted); } }