📄 ads.cs
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
// Copyright (c) Telligent Systems Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using CommunityServer.Components;
using System.Web.UI;
namespace CommunityServer.Controls {
// *********************************************************************
// Ads
//
/// <summary>
/// This server control is a placeholder where the user can add advertising.
/// </summary>
// ***********************************************************************/
public class Ads : SkinnedWebControl {
string skinFilename = "Skin-Ads.ascx";
Zones zone = Zones.StandardTop;
// *********************************************************************
// Ads
//
/// <summary>
/// Constructor
/// </summary>
// ***********************************************************************/
public Ads() : base() {
// Assign a default template name
if (SkinFilename == null)
SkinFilename = skinFilename;
}
// *********************************************************************
// CreateChildControls
//
/// <summary>
/// This event handler adds the children controls.
/// </summary>
// ***********************************************************************/
protected override void CreateChildControls() {
if( CSContext.Current.SiteSettings.EnableAds == false )
return;
// If the user is already authenticated we have no work to do
if (Page.Request.IsAuthenticated) {
if ( CSContext.Current.User.IsAdministrator || CSContext.Current.User.IsModerator )
return;
}
base.CreateChildControls();
}
// *********************************************************************
// Initializeskin
//
/// <summary>
/// Initialize the control template and populate the control with values
/// </summary>
// ***********************************************************************/
override protected void InitializeSkin(Control skin) {
switch (Zone) {
case Zones.StandardTop:
if (DisplayGoogleAd) {
skin.FindControl("GoogleAdsense").Visible = true;
} else {
skin.FindControl("StandardTop").Visible = true;
}
break;
case Zones.StandardBottom:
if (DisplayGoogleAd) {
skin.FindControl("GoogleAdsense").Visible = true;
} else {
skin.FindControl("StandardBottom").Visible = true;
}
break;
case Zones.Square:
skin.FindControl("Square").Visible = true;
break;
case Zones.Skyscraper:
skin.FindControl("Skyscraper").Visible = true;
break;
case Zones.Inline:
skin.FindControl("Inline").Visible = true;
break;
case Zones.GoogleAdsense:
skin.FindControl("GoogleAdsense").Visible = true;
break;
}
}
public bool DisplayGoogleAd {
get {
Random r = new Random();
if (r.Next(100) < googleRotationPercent)
return true;
return false;
}
}
int googleRotationPercent = 0;
public int GoogleRotationPercent {
get {
return googleRotationPercent;
}
set {
googleRotationPercent = value;
}
}
public Zones Zone {
get { return zone; }
set { zone = value; }
}
}
public enum Zones {
StandardTop,
StandardBottom,
Inline,
GoogleAdsense,
Skyscraper,
Square
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -