/// <summary> /// update portal skin. /// </summary> /// <param name="portalId">portal id.</param> /// <param name="themeFile">skin info.</param> /// <param name="scope">change skin or container.</param> public void ApplyTheme(int portalId, ThemeFileInfo themeFile, ApplyThemeScope scope) { var skinPath = themeFile.Path + ".ascx"; switch (themeFile.Type) { case ThemeType.Container: if ((scope & ApplyThemeScope.Site) == ApplyThemeScope.Site) { SkinController.SetSkin(SkinController.RootContainer, portalId, SkinType.Portal, skinPath); } if ((scope & ApplyThemeScope.Edit) == ApplyThemeScope.Edit) { SkinController.SetSkin(SkinController.RootContainer, portalId, SkinType.Admin, skinPath); } break; case ThemeType.Skin: if ((scope & ApplyThemeScope.Site) == ApplyThemeScope.Site) { SkinController.SetSkin(SkinController.RootSkin, portalId, SkinType.Portal, skinPath); } if ((scope & ApplyThemeScope.Edit) == ApplyThemeScope.Edit) { SkinController.SetSkin(SkinController.RootSkin, portalId, SkinType.Admin, skinPath); } DataCache.ClearPortalCache(portalId, true); break; } }
/// <summary> /// get skin files in the skin. /// </summary> /// <param name="portalSettings"></param> /// <param name="theme"></param> /// <returns></returns> public IList <ThemeFileInfo> GetThemeFiles(PortalSettings portalSettings, ThemeInfo theme) { var themePath = Path.Combine(Globals.ApplicationMapPath, theme.Path); var themeFiles = new List <ThemeFileInfo>(); if (Directory.Exists(themePath)) { bool fallbackSkin; if (theme.Type == ThemeType.Skin) { fallbackSkin = IsFallbackSkin(themePath); } else { fallbackSkin = IsFallbackContainer(themePath); } var strSkinType = themePath.IndexOf(Globals.HostMapPath, StringComparison.InvariantCultureIgnoreCase) != -1 ? "G" : "L"; var canDeleteSkin = SkinController.CanDeleteSkin(themePath, portalSettings.HomeDirectoryMapPath); var arrFiles = Directory.GetFiles(themePath, "*.ascx"); foreach (var strFile in arrFiles) { var file = strFile.ToLowerInvariant(); var themeFile = new ThemeFileInfo(); themeFile.ThemeName = theme.PackageName; themeFile.Type = theme.Type; themeFile.Level = theme.Level; var imagePath = string.Empty; foreach (var ext in ImageExtensions) { var path = Path.ChangeExtension(file, ext); if (File.Exists(path)) { imagePath = path; break; } } if (!string.IsNullOrEmpty(imagePath)) { themeFile.Thumbnail = CreateThumbnail(imagePath); } themeFile.Name = Path.GetFileNameWithoutExtension(file); themeFile.Path = FormatThemePath(portalSettings, themePath, Path.GetFileName(strFile), theme.Type); themeFile.CanDelete = (UserController.Instance.GetCurrentUserInfo().IsSuperUser || strSkinType == "L") && (!fallbackSkin && canDeleteSkin); themeFiles.Add(themeFile); } } return(themeFiles); }
/// <summary> /// delete a skin or container. /// </summary> /// <param name="portalSettings"></param> /// <param name="themeFile"></param> public void DeleteTheme(PortalSettings portalSettings, ThemeFileInfo themeFile) { var themePath = SkinController.FormatSkinSrc(themeFile.Path, portalSettings); var user = UserController.Instance.GetCurrentUserInfo(); if (!user.IsSuperUser && themePath.IndexOf("\\portals\\_default\\", StringComparison.InvariantCultureIgnoreCase) != Null.NullInteger) { throw new SecurityException("NoPermission"); } File.Delete(Path.Combine(Globals.ApplicationMapPath, themePath)); DataCache.ClearPortalCache(portalSettings.PortalId, true); }
public IFileInfo GetFileInfo(string subpath) { var result = new ThemeFileInfo(_serviceProvider, subpath); return(result.Exists ? result as IFileInfo : new NotFoundFileInfo(subpath)); }