⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 skinoptionscontrol.ascx.cs

📁 community server 源码
💻 CS
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.IO;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using CommunityServer.Blogs.Components;
using CommunityServer.Components;

namespace CommunityServer.ControlPanel.Controls.Blogs
{
	/// <summary>
	///		Summary description for SkinOptionsControl.
	/// </summary>
	public class SkinOptionsControl : UserControl
	{

		#region Public Properties

		public Weblog Weblog
		{
			get{return weblog;}
			set{weblog = value;}
		}

		#endregion

		#region Child Controls
		
		protected DropDownList Themes;
		protected HelpIcon HelpIcon1;
		protected FormLabel FormLabel1;
		protected FormLabel Formlabel2;
		protected HtmlGenericControl PreviewImage;
		protected HtmlGenericControl PreviewText;
		protected StatusMessage Status;
		protected HtmlTable previewtable;
		protected HtmlGenericControl SkinSelector;

		#endregion

		private const string PreivewImgTag = @"<img src=""{0}/{1}.png"" height=""150"" width=""200"" alt=""{1}.png Preview Image"" style=""border:solid 1px #CCCCCC;""/>";
		private const string ThemePath = @"{0}Blogs/{1}";
		private Weblog weblog;


		private void Page_Load(object sender, EventArgs e)
		{
			Themes.Attributes.Add("OnChange", "UpdatePreview();") ;
			AjaxManager.Register(this,"SkinOptionsControl");
				// Check if Themes are enabled
			if (WeblogConfiguration.Instance().EnableThemes)
			{
				if(!IsPostBack)
					PopulateThemes();
			}
			else
			{
				SkinSelector.Visible = false;
				previewtable.Visible = false;
				Status.Success = false;
				Status.Visible = true;
				Status.ResourceName = "CP_Blog_SkinOptions_ThemesNotEnabled";
			}
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		///		Required method for Designer support - do not modify
		///		the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.Load += new EventHandler(this.Page_Load);

		}
		#endregion
		
		private void PopulateThemes()
		{
			Themes.Items.Clear();
    
			string dirPath = Context.Server.MapPath(string.Concat(SiteUrls.Instance().Locations["Themes"], "/Blogs") );
    
			DirectoryInfo dirAllThemes = new DirectoryInfo(dirPath);
			foreach(DirectoryInfo dirTheme in dirAllThemes.GetDirectories())
			{
				DirectoryInfo dirStyle = new DirectoryInfo(Path.Combine(dirTheme.FullName, "Style"));
				if(dirStyle.Exists)
				{
					Themes.Items.Add(new ListItem(dirTheme.Name, dirTheme.Name.ToLower() + "@"));
					foreach(FileInfo fi in dirStyle.GetFiles("*.css"))
					{
                        if(string.Compare(fi.Name,"print.css", true) != 0)
                        {
                            string name = Path.GetFileNameWithoutExtension(fi.FullName).ToLower();
                            if( name != "style")
                            {
                                string themeText = string.Format("{0} - {1}", dirTheme.Name, name);
                                string themeValue = string.Format("{0}@{1}.css", dirTheme.Name, name);
                                Themes.Items.Add(new ListItem(themeText,themeValue.ToLower()));
                            }
                        }
					}
                        
				}
			}

			SetSelectedTheme(Weblog);

		}

		public void SetSelectedTheme(Weblog b)
		{
			string theme = string.Format("{0}@{1}", b.Theme,b.SecondaryCSS).ToLower().Trim();

			ListItem liTheme = Themes.Items.FindByValue(theme);
			if(liTheme != null)
				liTheme.Selected = true;
			
			PreviewImage.InnerHtml = GeneratePreviewImageString(Themes.SelectedValue);
			PreviewText.InnerHtml = SkinDescriptionContents(Themes.SelectedValue);
		}

		public void GetFormValues(Weblog w)
		{
			if (WeblogConfiguration.Instance().EnableThemes)
			{
				string[] theme = Themes.SelectedValue.Split('@');


				w.Theme = theme[0];
            
				if(theme.Length > 1)
					w.SecondaryCSS = theme[1];
				else
					w.SecondaryCSS = null;
			}
		}

		[AjaxMethod(IncludeControlValuesWithCallBack=false)]
		public string GetPreviewText(string skin)
		{
			return SkinDescriptionContents(skin);
		}

		[AjaxMethod(IncludeControlValuesWithCallBack=false)]
		public string GetPreviewImage(string skin)
		{
			return GeneratePreviewImageString(skin);
		}
		
		private string SkinDescriptionContents(string themeName)
		{
			string themePath = string.Format(ThemePath, SiteUrls.Instance().Locations["themes"], themeName.Split('@')[0]);
			string descFilePath = CSContext.Current.Context.Server.MapPath(string.Format("{0}/{1}.htm", themePath, themeName));
			if(!File.Exists(descFilePath))
				return "";

			StreamReader sr = File.OpenText(descFilePath);
			String s = sr.ReadToEnd();
			sr.Close() ;
			return s;

		}

	
		private string GeneratePreviewImageString(string themeName)
		{
			string themePath = string.Format(ThemePath, SiteUrls.Instance().Locations["themes"],  themeName.Split('@')[0]);
			return string.Format(PreivewImgTag, themePath, themeName);

		}

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -