Exemple #1
0
        public async Task <ActionResult> Remove(string pageName)
        {
            if (string.IsNullOrWhiteSpace(pageName))
            {
                throw new Error(this.__ResStr("noPageName", "No page name specified"));
            }
            PageDefinition page = await PageDefinition.LoadFromUrlAsync(pageName);

            if (page == null)
            {
                throw new Error(this.__ResStr("noPage", "Page \"{0}\" not found", pageName));
            }

            await PageDefinition.RemovePageDefinitionAsync(page.PageGuid);

            return(Reload(null, Reload: ReloadEnum.ModuleParts));
        }
Exemple #2
0
        // ISEARCHDYNAMICURLS
        // ISEARCHDYNAMICURLS
        // ISEARCHDYNAMICURLS

        public async Task KeywordsForDynamicUrlsAsync(ISearchWords searchWords)
        {
            using (this) {
                BlogConfigData config = await BlogConfigDataProvider.GetConfigAsync();

                List <DataProviderFilterInfo> filters = DataProviderFilterInfo.Join(null, new DataProviderFilterInfo {
                    Field = nameof(BlogEntry.Published), Operator = "==", Value = true
                });
                DataProviderGetRecords <BlogEntry> entries = await GetItemsAsync(0, 0, null, filters);

                foreach (BlogEntry entry in entries.Data)
                {
                    string url = await BlogConfigData.GetEntryCanonicalNameAsync(entry.Identity);

                    PageDefinition page = await PageDefinition.LoadFromUrlAsync(url);

                    if (page == null)
                    {
                        return;               // there is no such root page
                    }
                    if (!searchWords.WantPage(page))
                    {
                        return;
                    }

                    if (await searchWords.SetUrlAsync(url, page.PageSecurity, entry.Title, entry.DisplayableSummaryText, entry.DateCreated, entry.DateUpdated, page.IsAuthorized_View_Anonymous(), page.IsAuthorized_View_AnyUser()))
                    {
                        searchWords.AddObjectContents(entry);
                        using (BlogCommentDataProvider commentDP = new BlogCommentDataProvider(entry.Identity)) {
                            DataProviderGetRecords <BlogComment> comments = await commentDP.GetItemsAsync(0, 0, null, null);

                            foreach (BlogComment comment in comments.Data)
                            {
                                searchWords.AddObjectContents(comment);
                            }
                        }
                        await searchWords.SaveAsync();
                    }
                }
            }
        }
Exemple #3
0
        // ISITEMAPDYNAMICURLS
        // ISITEMAPDYNAMICURLS
        // ISITEMAPDYNAMICURLS

        public async Task FindDynamicUrlsAsync(AddDynamicUrlAsync addDynamicUrlAsync, Func <PageDefinition, bool> validForSiteMap)
        {
            using (this) {
                List <DataProviderFilterInfo> filters = DataProviderFilterInfo.Join(null, new DataProviderFilterInfo {
                    Field = nameof(BlogEntry.Published), Operator = "==", Value = true
                });
                DataProviderGetRecords <BlogEntry> entries = await GetItemsAsync(0, 0, null, filters);

                foreach (BlogEntry entry in entries.Data)
                {
                    string url = await BlogConfigData.GetEntryCanonicalNameAsync(entry.Identity);

                    PageDefinition page = await PageDefinition.LoadFromUrlAsync(url);

                    if (page == null)
                    {
                        return;               // there is no such root page
                    }
                    await addDynamicUrlAsync(page, url, entry.DateUpdated, page.SiteMapPriority, page.ChangeFrequency, entry);
                }
            }
        }
Exemple #4
0
        private async Task ExtractPageSectionAsync(List <string> lines, bool build)
        {
            for (; lines.Count > 0;)
            {
                // get the menu path (site url)
                string urlLine = lines.First();
                if (urlLine.StartsWith("::"))
                {
                    break; // start of a new section
                }
                ++_LineCounter; lines.RemoveAt(0);
                if (urlLine.Trim() == "")
                {
                    continue;
                }
                string[] s = urlLine.Split(new char[] { ' ' }, 2);
                if (s.Length != 2)
                {
                    throw TemplateError("Url {0} invalid", urlLine);
                }

                string user = s[0].Trim();
                string url  = s[1].Trim();

                // validate url
                if (url.Length == 0 || url[0] != '/')
                {
                    throw TemplateError("Url must start with / and can't be indented");
                }

                PageDefinition page = null;
                if (build)
                {
                    page = await PageDefinition.CreatePageDefinitionAsync(url);
                }
                else
                {
                    page = await PageDefinition.LoadFromUrlAsync(url);

                    if (page != null)
                    {
                        await PageDefinition.RemovePageDefinitionAsync(page.PageGuid);
                    }
                    page = new PageDefinition();
                }
                _CurrentPage = page;
                _CurrentUrl  = url;

                while (TryPageTitle(page, lines) || TryPageDescription(page, lines))
                {
                    ;
                }

                // Get the Menu Text
                if (lines.Count < 1)
                {
                    throw TemplateError("Menu missing");
                }
                string menu = lines.First(); ++_LineCounter; lines.RemoveAt(0);
                if (string.IsNullOrWhiteSpace(menu))
                {
                    throw TemplateError("Menu missing");
                }
                if (!char.IsWhiteSpace(menu[0]))
                {
                    throw TemplateError("Menu line must be indented");
                }
                menu = menu.Trim();

                // add a menu entry to the site menu
                if (menu != "-")
                {
                    if (build)
                    {
                        ModuleAction action = await AddMenuAsync(menu);

                        //if (string.IsNullOrWhiteSpace(action.Url)) // I don't remember why this was here
                        action.Url = url;
                    }
                    else
                    {
                        await RemoveMenuAsync(menu);
                    }
                }

                // Get the skin
                if (lines.Count < 1)
                {
                    throw TemplateError("Skin missing");
                }
                string skin = lines.First(); ++_LineCounter; lines.RemoveAt(0);
                if (string.IsNullOrWhiteSpace(skin))
                {
                    throw TemplateError("Skin missing");
                }
                if (!char.IsWhiteSpace(skin[0]))
                {
                    throw TemplateError("Skin line must be indented");
                }
                skin = skin.Trim();
                if (skin == "-")
                {
                    skin = ",,,";
                }
                string[] skinparts = skin.Split(new char[] { ',' });
                if (skinparts.Length != 4)
                {
                    throw TemplateError("Invalid skin format");
                }

                page.SelectedSkin.Collection = skinparts[0].Trim();
                if (page.SelectedSkin.Collection == "-")
                {
                    page.SelectedSkin.Collection = null;
                }
                page.SelectedSkin.FileName        = skinparts[1].Trim();
                page.SelectedPopupSkin.Collection = skinparts[2].Trim();
                if (page.SelectedPopupSkin.Collection == "-")
                {
                    page.SelectedPopupSkin.Collection = null;
                }
                page.SelectedPopupSkin.FileName = skinparts[3].Trim();

                SerializableList <PageDefinition.AllowedRole> roles = new SerializableList <PageDefinition.AllowedRole>();
                switch (user)
                {
                case "Administrator":
                    roles.Add(new PageDefinition.AllowedRole {
                        RoleId = Resource.ResourceAccess.GetAdministratorRoleId(), View = PageDefinition.AllowedEnum.Yes, Edit = PageDefinition.AllowedEnum.Yes, Remove = PageDefinition.AllowedEnum.Yes,
                    });
                    break;

                case "User":
                    roles.Add(new PageDefinition.AllowedRole {
                        RoleId = Resource.ResourceAccess.GetUserRoleId(), View = PageDefinition.AllowedEnum.Yes,
                    });
                    roles.Add(new PageDefinition.AllowedRole {
                        RoleId = Resource.ResourceAccess.GetEditorRoleId(), View = PageDefinition.AllowedEnum.Yes, Edit = PageDefinition.AllowedEnum.Yes,
                    });
                    roles.Add(new PageDefinition.AllowedRole {
                        RoleId = Resource.ResourceAccess.GetAdministratorRoleId(), View = PageDefinition.AllowedEnum.Yes, Edit = PageDefinition.AllowedEnum.Yes, Remove = PageDefinition.AllowedEnum.Yes,
                    });
                    break;

                case "Anonymous":
                    roles.Add(new PageDefinition.AllowedRole {
                        RoleId = Resource.ResourceAccess.GetAnonymousRoleId(), View = PageDefinition.AllowedEnum.Yes,
                    });
                    roles.Add(new PageDefinition.AllowedRole {
                        RoleId = Resource.ResourceAccess.GetEditorRoleId(), View = PageDefinition.AllowedEnum.Yes, Edit = PageDefinition.AllowedEnum.Yes,
                    });
                    roles.Add(new PageDefinition.AllowedRole {
                        RoleId = Resource.ResourceAccess.GetAdministratorRoleId(), View = PageDefinition.AllowedEnum.Yes, Edit = PageDefinition.AllowedEnum.Yes, Remove = PageDefinition.AllowedEnum.Yes,
                    });
                    break;

                case "Anonymous+User":
                    roles.Add(new PageDefinition.AllowedRole {
                        RoleId = Resource.ResourceAccess.GetAnonymousRoleId(), View = PageDefinition.AllowedEnum.Yes,
                    });
                    roles.Add(new PageDefinition.AllowedRole {
                        RoleId = Resource.ResourceAccess.GetUserRoleId(), View = PageDefinition.AllowedEnum.Yes,
                    });
                    roles.Add(new PageDefinition.AllowedRole {
                        RoleId = Resource.ResourceAccess.GetEditorRoleId(), View = PageDefinition.AllowedEnum.Yes, Edit = PageDefinition.AllowedEnum.Yes,
                    });
                    roles.Add(new PageDefinition.AllowedRole {
                        RoleId = Resource.ResourceAccess.GetAdministratorRoleId(), View = PageDefinition.AllowedEnum.Yes, Edit = PageDefinition.AllowedEnum.Yes, Remove = PageDefinition.AllowedEnum.Yes,
                    });
                    break;

                default:
                    throw TemplateError("User {0} invalid", user);
                }
                page.AllowedRoles = roles;

                // Get zero, one or more modules (add to Main section)
                for (; lines.Count > 0;)
                {
                    string modsLine = lines.First();
                    if (string.IsNullOrWhiteSpace(modsLine))
                    {
                        ++_LineCounter; lines.RemoveAt(0);
                        continue;
                    }
                    if (!char.IsWhiteSpace(modsLine[0]))
                    {
                        break;// not a module - module lines must be indented
                    }
                    // Load assembly
                    ++_LineCounter; lines.RemoveAt(0);// accept as module line
                    string[] parts  = modsLine.Split(new char[] { ':' });
                    string   pane   = null;
                    string   modDef = null;
                    if (parts.Length == 1)
                    {
                        pane   = Globals.MainPane;
                        modDef = parts[0].Trim();
                    }
                    else if (parts.Length == 2)
                    {
                        pane = parts[0].Trim();
                        if (pane == "-")
                        {
                            pane = Globals.MainPane;
                        }
                        modDef = parts[1].Trim();
                    }
                    else
                    {
                        throw TemplateError("Invalid \"pane: module definition\"");
                    }
                    ModuleDefinition mod = await EvaluateModuleAsmTypeExpression(modDef);

                    page.AddModule(pane, mod);

                    for (; lines.Count > 0;)
                    {
                        // add variable customizations (if any)
                        string varLine = lines.First();
                        if (string.IsNullOrWhiteSpace(varLine))
                        {
                            ++_LineCounter; lines.RemoveAt(0);
                            continue;
                        }
                        // if this line is more indented than the module line, it must be a variable line
                        if (varLine.Length - varLine.TrimStart(new char[] { ' ' }).Length <= modsLine.Length - modsLine.TrimStart(new char[] { ' ' }).Length)
                        {
                            break;
                        }
                        // process variables
                        ++_LineCounter; lines.RemoveAt(0);// accept as variable line
                        if (varLine.Trim() == "")
                        {
                            continue;
                        }
                        string[] sv = varLine.Split(new char[] { '=' }, 2);
                        if (varLine.Trim().EndsWith(")"))  // method call
                        {
                            varLine = varLine.Trim();
                            if (build)
                            {
                                await InvokeMethodAsync(varLine, varLine, mod);
                            }
                        }
                        else if (sv.Length >= 2)     // variable assignment
                        {
                            if (build)
                            {
                                AssignVariable(mod, sv[0].Trim(), sv[1].Trim());
                            }
                        }
                        else
                        {
                            throw TemplateError("Variable assignment invalid");
                        }
                    }
                }
                if (build)
                {
                    await page.SaveAsync();
                }
                _CurrentPage = null;
                _CurrentUrl  = null;
            }
        }
Exemple #5
0
        public async Task <ActionResult> PageBar()
        {
            Model model;

            if (Manager.EditMode)
            {
                model = new Model {
                    PagePattern       = Module.PagePattern,
                    PageList          = Module.PageList,
                    Style             = Module.Style,
                    ContentPane       = Module.ContentPane,
                    UseSkinFormatting = Module.UseSkinFormatting,
                    DefaultImage      = Module.DefaultImage,
                    DefaultImage_Data = Module.DefaultImage_Data
                };
            }
            else
            {
                model = new Model {
                    PanelInfo = new Models.PageBarInfo()
                    {
                        Style             = Module.Style,
                        ContentPane       = Module.ContentPane,
                        UseSkinFormatting = Module.UseSkinFormatting,
                        Panels            = await GetPanelsAsync()
                    }
                };

                // Check whether current page contents are accessible and get pane contents
                Uri    contentUri = null;
                string contentUrl;
                Manager.TryGetUrlArg <string>("!ContentUrl", out contentUrl);
                if (!string.IsNullOrWhiteSpace(contentUrl))
                {
                    if (contentUrl.StartsWith("/"))
                    {
                        contentUrl = Manager.CurrentSite.MakeUrl(contentUrl);
                    }
                    contentUri = new Uri(contentUrl);
                }
                else
                {
                    if (model.PanelInfo.Panels.Count > 0)
                    {
                        contentUri = new Uri(model.PanelInfo.Panels[0].Url);
                    }
                }
                if (contentUri != null)
                {
                    PageDefinition page = await PageDefinition.LoadFromUrlAsync(contentUri.AbsolutePath);

                    if (page != null)
                    {
                        if (page.IsAuthorized_View())
                        {
                            model.PanelInfo.ContentUri  = contentUri;
                            model.PanelInfo.ContentPage = page;
                        }
                        else
                        {
                            if (!Manager.HaveUser)
                            {
                                return(RedirectToUrl(Manager.CurrentSite.LoginUrl));
                            }
                        }
                    }
                }
            }
            return(View(model));
        }