/// <summary> /// 按查询字符串得到广告列表 /// </summary> /// <param name="selectstr">查询字符串</param> /// <returns>广告列表</returns> private static AdShowInfo[] GetAdsTable(string selectstr) { Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService(); DataTable dt = cache.RetrieveObject("/Advertisements") as DataTable; if (dt == null) { dt = DatabaseProvider.GetInstance().GetAdsTable(); cache.AddObject("/Advertisements", dt); } DataRow[] drs = dt.Select(selectstr); int adlength = drs.Length; AdShowInfo[] adarray = new AdShowInfo[adlength]; for (int i = 0; i < adlength; i++) { adarray[i] = new AdShowInfo(); adarray[i].Advid = Convert.ToInt32(drs[i]["advid"].ToString()); adarray[i].Displayorder = Convert.ToInt32(drs[i]["displayorder"].ToString()); adarray[i].Code = drs[i]["code"].ToString().Trim(); adarray[i].Parameters = drs[i]["parameters"].ToString().Trim(); } return(adarray); }
/// <summary> /// 获取显示广告信息 /// </summary> /// <param name="adshowArray">显示的广告数据</param> /// <param name="floor">获取指定楼层的帖内广告</param> /// <param name="inPostAdType">帖内广告类型 0:帖内下方的广告 1:帖内上方的广告 2:帖内右方的广告</param> /// <returns>广告信息</returns> public static string GetAdShowInfoXMLByFloor(AdShowInfo[] adshowArray, int floor, int inPostAdType) { string adsMsg = ""; Random random = new Random(); //取帖内下方广告 List <AdShowInfo> tmp = new List <AdShowInfo>(); foreach (AdShowInfo adshow in adshowArray)//可用的帖内下方广告 { string[] parameter = Utils.SplitString(adshow.Parameters.ToString().Trim(), "|", 9); if (Utils.StrToInt(parameter[7], -1) == inPostAdType) { //parameter[8]:possibleflooridlist if (Utils.InArray(floor.ToString(), parameter[8], ",") || parameter[8] == "0") { tmp.Add(adshow); } } } if (tmp.Count > 0) { AdShowInfo ad = tmp[random.Next(0, tmp.Count)]; adsMsg = string.Format("<ad_thread{0}><![CDATA[{1}]]></ad_thread{0}>", inPostAdType, ad.Code); } return(adsMsg); }
public static string[] GetPageWordAd(string pagename, int forumid) { AdShowInfo[] adsTable = GetAdsTable(GetSelectStr(pagename, forumid, AdType.PageWordAd)); if (adsTable.Length < 1) { return(new string[0]); } List <string> list = new List <string>(); AdShowInfo[] array = adsTable; for (int i = 0; i < array.Length; i++) { AdShowInfo adShowInfo = array[i]; list.Add(adShowInfo.Code); } return(list.ToArray()); }
public static string GetAdShowInfoXMLByFloor(AdShowInfo[] adshowArray, int floor, int inPostAdType) { string result = ""; Random random = new Random(); List <AdShowInfo> list = new List <AdShowInfo>(); for (int i = 0; i < adshowArray.Length; i++) { AdShowInfo adShowInfo = adshowArray[i]; string[] array = Utils.SplitString(adShowInfo.Parameters.ToString().Trim(), "|", 9); if (Utils.StrToInt(array[7], -1) == inPostAdType && (Utils.InArray(floor.ToString(), array[8], ",") || array[8] == "0")) { list.Add(adShowInfo); } } if (list.Count > 0) { AdShowInfo adShowInfo2 = list[random.Next(0, list.Count)]; result = string.Format("<ad_thread{0}><![CDATA[{1}]]></ad_thread{0}>", inPostAdType, adShowInfo2.Code); } return(result); }
private static AdShowInfo[] GetAdsTable(string selectstr) { var cacheService = DNTCache.Current; DataTable dataTable = cacheService.RetrieveObject(CacheKeys.FORUM_ADVERTISEMENTS) as DataTable; if (dataTable == null) { dataTable = Advertisenments.GetAdsTable(); cacheService.AddObject(CacheKeys.FORUM_ADVERTISEMENTS, dataTable); } DataRow[] array = dataTable.Select(selectstr); AdShowInfo[] array2 = new AdShowInfo[array.Length]; for (int i = 0; i < array.Length; i++) { array2[i] = new AdShowInfo(); array2[i].Advid = Utils.StrToInt(array[i]["advid"].ToString(), 0); array2[i].Displayorder = Utils.StrToInt(array[i]["displayorder"].ToString(), 0); array2[i].Code = array[i]["code"].ToString().Trim(); array2[i].Parameters = array[i]["parameters"].ToString().Trim(); } return(array2); }
public static string GetAdShowInfo(AdShowInfo[] adshowArray, int count, int inPostAdType) { string text = ""; Random random = new Random(); for (int i = 1; i <= count; i++) { List <AdShowInfo> list = new List <AdShowInfo>(); for (int j = 0; j < adshowArray.Length; j++) { AdShowInfo adShowInfo = adshowArray[j]; string[] array = Utils.SplitString(adShowInfo.Parameters.Trim(), "|", 9); if (Utils.StrToInt(array[7], -1) == inPostAdType && (Utils.InArray(i.ToString(), array[8], ",") || array[8] == "0")) { list.Add(adShowInfo); } } if (list.Count > 0) { switch (inPostAdType) { case 0: text += string.Format("<div class=\"ad_textlink1\" id=\"ad_thread1_{0}_none\">{1}</div>\r\n", i, list[random.Next(0, list.Count)].Code); break; case 1: text += string.Format("<div class=\"ad_textlink2\" id=\"ad_thread2_{0}_none\">{1}</div>\r\n", i, list[random.Next(0, list.Count)].Code); break; default: text += string.Format("<div class=\"ad_pip\" id=\"ad_thread3_{0}_none\">{1}</div>\r\n", i, list[random.Next(0, list.Count)].Code); break; } } } return(text); }
/// <summary> /// 按查询字符串得到广告列表 /// </summary> /// <param name="selectstr">查询字符串</param> /// <returns>广告列表</returns> private static AdShowInfo[] GetAdsTable(string selectstr) { Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService(); DataTable dt = cache.RetrieveObject("/Forum/Advertisements") as DataTable; if (dt == null) { dt = Discuz.Data.Advertisenments.GetAdsTable(); cache.AddObject("/Forum/Advertisements", dt); } DataRow[] drs = dt.Select(selectstr); AdShowInfo[] adarray = new AdShowInfo[drs.Length]; for (int i = 0; i < drs.Length; i++) { adarray[i] = new AdShowInfo(); adarray[i].Advid = Utils.StrToInt(drs[i]["advid"].ToString(), 0); adarray[i].Displayorder = Utils.StrToInt(drs[i]["displayorder"].ToString(), 0); adarray[i].Code = drs[i]["code"].ToString().Trim(); adarray[i].Parameters = drs[i]["parameters"].ToString().Trim(); } return(adarray); }
/// <summary> /// 获取指定楼层的帖内广告 /// </summary> /// <param name="pagename">页面名称</param> /// <param name="forumid">版块id</param> /// <param name="templatepath">模板路径</param> /// <param name="floor">获取指定楼层的帖内广告</param> public static string GetInPostAdXMLByFloor(string pagename, int forumid, string templatepath, int floor) { string selectstr = GetSelectStr(pagename, forumid, AdType.InPostAd); AdShowInfo[] adshowArray = GetAdsTable(selectstr); StringBuilder sb = new StringBuilder(); if (adshowArray.Length > 0) { Random random = new Random(); //取帖内下方广告 #if NET1 AdShowInfoCollection tmp = new AdShowInfoCollection(); #else List <AdShowInfo> tmp = new List <AdShowInfo>(); #endif foreach (AdShowInfo adshow in adshowArray)//可用的帖内下方广告 { string[] parameter = Utils.SplitString(adshow.Parameters.ToString().Trim(), "|", 9); int position = Utils.StrToInt(parameter[7], -1); if (position == 0) { string possibleflooridlist = parameter[8]; if (Utils.InArray(floor.ToString(), possibleflooridlist, ",") || possibleflooridlist == "0") { tmp.Add(adshow); } } } if (tmp.Count > 0) { int number = random.Next(0, tmp.Count); AdShowInfo ad = tmp[number]; sb.Append(string.Format("<ad_thread1><![CDATA[{0}]]></ad_thread1>", ad.Code)); } tmp.Clear();//帖内上方 foreach (AdShowInfo adshow in adshowArray) { string[] parameter = Utils.SplitString(adshow.Parameters.ToString().Trim(), "|", 9); int position = Utils.StrToInt(parameter[7], -1); if (position == 1) { string possibleflooridlist = parameter[8]; if (Utils.InArray(floor.ToString(), possibleflooridlist, ",") || possibleflooridlist == "0") { tmp.Add(adshow); } } } if (tmp.Count > 0) { int number = random.Next(0, tmp.Count); AdShowInfo ad = tmp[number]; sb.Append(string.Format("<ad_thread2><![CDATA[{0}]]></ad_thread2>", ad.Code)); } tmp.Clear();//帖内右侧 foreach (AdShowInfo adshow in adshowArray) { string[] parameter = Utils.SplitString(adshow.Parameters.ToString().Trim(), "|", 9); int position = Utils.StrToInt(parameter[7], -1); if (position == 2) { string possibleflooridlist = parameter[8]; if (Utils.InArray(floor.ToString(), possibleflooridlist, ",") || possibleflooridlist == "0") { tmp.Add(adshow); } } } if (tmp.Count > 0) { int number = random.Next(0, tmp.Count); AdShowInfo ad = tmp[number]; sb.Append(string.Format("<ad_thread3><![CDATA[{0}]]></ad_thread3>", ad.Code)); } } return(sb.ToString()); }
/// <summary> /// 返回贴内广告 /// </summary> /// <param name="pagename">页面名称</param> /// <param name="forumid">版块id</param> /// <param name="templatepath">模板路径</param> /// <param name="count">总数</param> /// <returns>贴内广告内容</returns> public static string GetInPostAd(string pagename, int forumid, string templatepath, int count) { string selectstr = GetSelectStr(pagename, forumid, AdType.InPostAd); AdShowInfo[] adshowArray = GetAdsTable(selectstr); StringBuilder sb = new StringBuilder(); if (adshowArray.Length > 0) { #region 原始代码 sb.Append("<div style=\"display: none;\" id=\"ad_none\">\r\n"); Random random = new Random(); for (int i = 1; i <= count; i++) {//帖内下方的广告 #if NET1 AdShowInfoCollection tmp = new AdShowInfoCollection(); #else List <AdShowInfo> tmp = new List <AdShowInfo>(); #endif string[] parameter; foreach (AdShowInfo adshow in adshowArray) { parameter = Utils.SplitString(adshow.Parameters.Trim(), "|", 9); int position = Utils.StrToInt(parameter[7], -1); if (position == 0) { string possibleflooridlist = parameter[8]; if (Utils.InArray(i.ToString(), possibleflooridlist, ",") || possibleflooridlist == "0") { tmp.Add(adshow); } } } if (tmp.Count > 0) { int number = random.Next(0, tmp.Count); AdShowInfo ad = tmp[number]; sb.Append(string.Format("<div class=\"ad_textlink1\" id=\"ad_thread1_{0}_none\">{1}</div>\r\n", i, ad.Code)); } } for (int i = 1; i <= count; i++) {//帖内上方的广告 #if NET1 AdShowInfoCollection tmp = new AdShowInfoCollection(); #else List <AdShowInfo> tmp = new List <AdShowInfo>(); #endif string[] parameter; foreach (AdShowInfo adshow in adshowArray) { parameter = Utils.SplitString(adshow.Parameters.Trim(), "|", 9); int position = Utils.StrToInt(parameter[7], -1); if (position == 1) { string possibleflooridlist = parameter[8]; if (Utils.InArray(i.ToString(), possibleflooridlist, ",") || possibleflooridlist == "0") { tmp.Add(adshow); } } } if (tmp.Count > 0) { int number = random.Next(0, tmp.Count); AdShowInfo ad = tmp[number]; sb.Append(string.Format("<div class=\"ad_textlink2\" id=\"ad_thread2_{0}_none\">{1}</div>\r\n", i, ad.Code)); } } for (int i = 1; i <= count; i++) {//帖内右方的广告 #if NET1 AdShowInfoCollection tmp = new AdShowInfoCollection(); #else List <AdShowInfo> tmp = new List <AdShowInfo>(); #endif foreach (AdShowInfo adshow in adshowArray) { string[] parameter = Utils.SplitString(adshow.Parameters.Trim(), "|", 9); int position = Utils.StrToInt(parameter[7], -1); if (position == 2) { string possibleflooridlist = parameter[8]; if (Utils.InArray(i.ToString(), possibleflooridlist, ",") || possibleflooridlist == "0") { tmp.Add(adshow); } } } if (tmp.Count > 0) { int number = random.Next(0, tmp.Count); AdShowInfo ad = tmp[number]; sb.Append(string.Format("<div class=\"ad_pip\" id=\"ad_thread3_{0}_none\">{1}</div>\r\n", i, ad.Code)); } } sb.Append("</div>"); sb.Append("<script type='text/javascript' src='javascript/template_inforumad.js'></script>\r\n"); } return(sb.ToString()); #endregion }