📄 ajax.cs
字号:
namespace PowerEasy.WebSite
{
using PowerEasy.Common;
using PowerEasy.Components;
using PowerEasy.Contents;
using PowerEasy.Enumerations;
using PowerEasy.Model.Contents;
using PowerEasy.Model.TemplateProc;
using PowerEasy.Model.UserManage;
using PowerEasy.Templates;
using PowerEasy.UserManage;
using PowerEasy.Web.UI;
using System;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Security;
using System.Xml;
public class Ajax : DynamicPage
{
private void AddComment(XmlDocument ixml)
{
CommentInfo commentInfo = new CommentInfo();
commentInfo.CommentTitle = (ixml.DocumentElement.SelectSingleNode("//commenttitle") == null) ? "" : ixml.DocumentElement.SelectSingleNode("//commenttitle").InnerText.Trim();
if (!HttpContext.Current.User.Identity.IsAuthenticated)
{
commentInfo.UserName = "游客";
}
else
{
commentInfo.UserName = PEContext.Current.User.UserName;
}
commentInfo.Content = (ixml.DocumentElement.SelectSingleNode("//content") == null) ? "" : ixml.DocumentElement.SelectSingleNode("//content").InnerText.Trim();
commentInfo.Email = (ixml.DocumentElement.SelectSingleNode("//email") == null) ? "" : ixml.DocumentElement.SelectSingleNode("//email").InnerText.Trim();
commentInfo.Face = (ixml.DocumentElement.SelectSingleNode("//face") == null) ? "" : ixml.DocumentElement.SelectSingleNode("//face").InnerText.Trim();
commentInfo.GeneralId = (ixml.DocumentElement.SelectSingleNode("//gid") == null) ? 0 : DataConverter.CLng(ixml.DocumentElement.SelectSingleNode("//gid").InnerText.Trim());
commentInfo.NodeId = (ixml.DocumentElement.SelectSingleNode("//nid") == null) ? 0 : DataConverter.CLng(ixml.DocumentElement.SelectSingleNode("//nid").InnerText.Trim());
commentInfo.TopicId = (ixml.DocumentElement.SelectSingleNode("//tid") == null) ? 0 : DataConverter.CLng(ixml.DocumentElement.SelectSingleNode("//tid").InnerText.Trim());
commentInfo.IsPrivate = (ixml.DocumentElement.SelectSingleNode("//private") == null) || DataConverter.CBool(ixml.DocumentElement.SelectSingleNode("//private").InnerText.Trim());
commentInfo.Position = (ixml.DocumentElement.SelectSingleNode("//position") == null) ? 0 : DataConverter.CLng(ixml.DocumentElement.SelectSingleNode("//position").InnerText.Trim());
commentInfo.Score = (ixml.DocumentElement.SelectSingleNode("//score") == null) ? 3 : DataConverter.CLng(ixml.DocumentElement.SelectSingleNode("//score").InnerText.Trim());
commentInfo.IP = this.GetClientIP();
commentInfo.UpdateDateTime = DateTime.Now.ToLocalTime();
commentInfo.ReplyUserName = (ixml.DocumentElement.SelectSingleNode("//username") == null) ? "游客" : ixml.DocumentElement.SelectSingleNode("//username").InnerText.Trim();
int num = string.Compare(commentInfo.UserName, "游客", true);
string str = "";
NodeInfo cacheNodeById = Nodes.GetCacheNodeById(ContentManage.GetCommonModelInfoById(commentInfo.GeneralId).NodeId);
commentInfo.Status = cacheNodeById.Settings.CommentNeedCheck;
UserPurviewInfo userPurview = null;
if (num != 0)
{
userPurview = PEContext.Current.User.UserInfo.UserPurview;
if (userPurview.CommentNeedCheck)
{
commentInfo.Status = true;
}
else
{
commentInfo.Status = !cacheNodeById.Settings.CommentNeedCheck;
}
}
else if (!cacheNodeById.Settings.EnableTouristsComment)
{
str = "noTourists";
}
else
{
commentInfo.Status = !cacheNodeById.Settings.CommentNeedCheck;
}
bool enableComment = false;
bool commentNeedCheck = false;
if (userPurview != null)
{
enableComment = userPurview.EnableComment;
commentNeedCheck = userPurview.CommentNeedCheck;
}
if (string.IsNullOrEmpty(str))
{
if (cacheNodeById.Settings.EnableComment || enableComment)
{
if (Comment.Add(commentInfo))
{
if (commentInfo.Status || commentNeedCheck)
{
str = "ok";
}
else
{
str = "check";
}
}
else
{
str = "err";
}
}
else
{
str = "nopurview";
}
}
XmlTextWriter writer = new XmlTextWriter(HttpContext.Current.Response.OutputStream, Encoding.UTF8);
writer.Formatting = Formatting.Indented;
writer.Indentation = 4;
writer.WriteStartDocument();
writer.WriteStartElement("root", "");
writer.WriteElementString("status", str);
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Close();
}
private void AddPKZone(XmlDocument ixml)
{
int num = (ixml.DocumentElement.SelectSingleNode("//commentid") == null) ? 0 : Convert.ToInt32(ixml.DocumentElement.SelectSingleNode("//commentid").InnerText.Trim());
if (num > 0)
{
CommentPKZoneInfo commentPKZoneInfo = new CommentPKZoneInfo();
commentPKZoneInfo.CommentId = num;
commentPKZoneInfo.Content = (ixml.DocumentElement.SelectSingleNode("//content") == null) ? "" : ixml.DocumentElement.SelectSingleNode("//content").InnerText.Trim();
commentPKZoneInfo.Position = (ixml.DocumentElement.SelectSingleNode("//position") == null) ? 0 : Convert.ToInt32(ixml.DocumentElement.SelectSingleNode("//position").InnerText.Trim());
commentPKZoneInfo.IP = this.GetClientIP();
commentPKZoneInfo.UpdateTime = DateTime.Now;
if (string.IsNullOrEmpty(PEContext.Current.User.UserName))
{
commentPKZoneInfo.UserName = "匿名发表";
}
else
{
commentPKZoneInfo.UserName = PEContext.Current.User.UserName;
}
CommentPKZone.Add(commentPKZoneInfo);
}
XmlTextWriter writer = new XmlTextWriter(HttpContext.Current.Response.OutputStream, Encoding.UTF8);
writer.Formatting = Formatting.Indented;
writer.Indentation = 4;
writer.WriteStartDocument();
writer.WriteStartElement("root", "");
if (num > 0)
{
writer.WriteElementString("status", "ok");
}
else
{
writer.WriteElementString("status", "err");
}
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Close();
}
private static string ContentLabelProc(string getlabel, string lrootpath, string lpagename, int lpage)
{
if (string.IsNullOrEmpty(getlabel))
{
return string.Empty;
}
getlabel = getlabel.Replace("{", "<").Replace("}", ">");
XmlDocument document = new XmlDocument();
LabelInfo labelInfo = new LabelInfo();
labelInfo.RootPath = lrootpath;
labelInfo.PageName = lpagename;
labelInfo.Page = lpage;
try
{
document.LoadXml(getlabel);
foreach (XmlAttribute attribute in document.FirstChild.Attributes)
{
labelInfo.OriginalData[attribute.Name] = attribute.Value;
}
}
catch (XmlException exception)
{
return ("[err:内容标签" + getlabel.Replace("<", string.Empty).Replace("/>", string.Empty) + "错,原因:" + exception.Message + "]");
}
string key = "CK_Label_TransformCacheData_" + labelInfo.OriginalData["id"] + "_" + labelInfo.OriginalData["cacheid"];
int seconds = DataConverter.CLng(labelInfo.OriginalData["cachetime"]);
if ((seconds > 0) && (SiteCache.Get(key) != null))
{
labelInfo = (LabelInfo) SiteCache.Get(key);
}
else
{
labelInfo = LabelTransform.GetLabel(labelInfo);
if (seconds > 0)
{
SiteCache.Insert(key, labelInfo, seconds);
}
}
return labelInfo.LabelContent.ToString();
}
private string GetClientIP()
{
string userHostAddress = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (string.IsNullOrEmpty(userHostAddress))
{
userHostAddress = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
}
if (string.IsNullOrEmpty(userHostAddress))
{
userHostAddress = PEContext.Current.UserHostAddress;
}
return userHostAddress;
}
private string GetSigninStatus(int generalId)
{
if (!PEContext.Current.User.Identity.IsAuthenticated)
{
return "NoLogin";
}
SigninLogInfo signinLog = SigninLog.GetSigninLog(generalId, PEContext.Current.User.UserName);
if (signinLog.IsNull)
{
return "NoSignin";
}
if (signinLog.IsSignin)
{
return "Signined";
}
return "NotSignin";
}
private void LoginCheck()
{
XmlTextWriter writer = new XmlTextWriter(HttpContext.Current.Response.OutputStream, Encoding.UTF8);
writer.Formatting = Formatting.Indented;
writer.Indentation = 4;
writer.WriteStartDocument();
writer.WriteStartElement("root", "");
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
writer.WriteElementString("status", "ok");
UserPrincipal user = PEContext.Current.User;
writer.WriteElementString("username", user.UserName);
writer.WriteElementString("usergroup", user.UserInfo.GroupName);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -