/* 編輯的預覽按鈕和列表頁的預覽都訪問這個方法 * 1. * */ public HttpResponseBase GetPreviewHtml() { string html = string.Empty; string replaceStr = string.Empty; string contentStr = string.Empty; string templateStr = string.Empty; string recommendStr = string.Empty; string previewStr = string.Empty; string editStr = string.Empty; try { _edmContentNewMgr = new EdmContentNewMgr(mySqlConnectionString); EdmContentNew query = new EdmContentNew(); //將傳過來的html加上根據當前登入者的id獲得的推薦html替換掉content_url中的替換符 if (!string.IsNullOrEmpty(Request.Params["content_id"])) { query.content_id = Convert.ToInt32(Request.Params["content_id"]); string content_url = _edmContentNewMgr.GetContentUrlByContentId(query.content_id); if (!string.IsNullOrEmpty(content_url)) { #region 獲取網頁內容 HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(content_url); httpRequest.Timeout = 9000; httpRequest.Method = "GET"; HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse(); StreamReader sr = new StreamReader(httpResponse.GetResponseStream(), System.Text.Encoding.GetEncoding("UTF-8")); contentStr = sr.ReadToEnd(); #endregion } else { contentStr = ""; } } //列表頁的預覽按鈕不進這個方法 if (!string.IsNullOrEmpty(Request.Params["template_id"])) { query.template_id = Convert.ToInt32(Request.Params["template_id"]); edmtemplatemgr = new EdmTemplateMgr(mySqlConnectionString); if (edmtemplatemgr.GetStaticTemplate(query.template_id)) { recommendStr = string.Empty; } else { recommendStr = _edmContentNewMgr.GetRecommendHtml(Convert.ToUInt32((Session["caller"] as Caller).user_id)); } } //獲取template_data(編輯器中的內容或者是表中的template_data) if (!string.IsNullOrEmpty(Request.Params["template_data"])) { templateStr = Request.Params["template_data"]; } else { templateStr = _edmContentNewMgr.GetHtml(query); } //編輯的預覽按鈕不進這個方法 //根據user_id獲得精準推薦 if (!string.IsNullOrEmpty(Request.Params["static_template"])) { if (Request.Params["static_template"] == "0")// 動態範本,精準推薦 { recommendStr = _edmContentNewMgr.GetRecommendHtml(Convert.ToUInt32((Session["caller"] as Caller).user_id)); } else { recommendStr = string.Empty; } } //替換符 DataTable _dt = _edmContentNewMgr.GetPraraData(1); if (_dt != null && _dt.Rows.Count > 0) { replaceStr = _dt.Rows[0][0].ToString(); } else { replaceStr = " "; } //分隔符 DataTable _dtEdit = _edmContentNewMgr.GetPraraData(3); if (_dtEdit != null && _dtEdit.Rows.Count > 0) { editStr = _dtEdit.Rows[0][0].ToString(); } else { editStr = " "; } templateStr = templateStr.Replace(editStr,"") + recommendStr; if (Request.Params["checked"] == "true") { if (!string.IsNullOrEmpty(contentStr)) { previewStr = contentStr.Replace(replaceStr, templateStr) + subscribe_url; } else { previewStr = templateStr + subscribe_url; } } else { if (!string.IsNullOrEmpty(contentStr)) { previewStr = contentStr.Replace(replaceStr, templateStr); } else { previewStr = templateStr; } } } catch (Exception ex) { Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage(); logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message); logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name; log.Error(logMessage); previewStr = ""; } this.Response.Clear(); this.Response.Write(previewStr); this.Response.End(); return this.Response; }
public HttpResponseBase GetHtml() { string htmlStr = string.Empty; try { EdmContentNew query = new EdmContentNew(); if (!string.IsNullOrEmpty(Request.Params["content_id"])) { query.content_id = Convert.ToInt32(Request.Params["content_id"]); } if (!string.IsNullOrEmpty(Request.Params["template_id"])) { query.template_id = Convert.ToInt32(Request.Params["template_id"]); } _edmContentNewMgr = new EdmContentNewMgr(mySqlConnectionString); htmlStr=_edmContentNewMgr.GetHtml(query); htmlStr = Server.HtmlDecode(Server.HtmlDecode(htmlStr)); } catch (Exception ex) { Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage(); logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message); logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name; log.Error(logMessage); } this.Response.Clear(); this.Response.Write(htmlStr); this.Response.End(); return this.Response; }