<!--#include file="conn.asp"-->
<!--#include file="check.asp"-->
<!--#include file="../sub.asp"-->
<%
if session("flag")>0 then
   Response.Write("<br><br><br><center>对不起。你没有权限进入此页面！！！</center>")
   Response.end 
END IF
%>
<%
aaas1=Request.ServerVariables("SERVER_NAME")
aaas2=Request.ServerVariables("URL")
aaas2=replace(aaas2,"admin/newsadd2.asp","")
Dim strData
Dim intFieldCount
Dim i

intFieldCount = Request.Form("hdnCount")

For i=1 To intFieldCount
content = content & Request.Form("hdnBigfield" & i)
Next
content=replace(content,"http://"&xpurl&"/uploadfile/","uploadfile/")
content=replace(content,"http://"&aaas1&aaas2&"uploadfile/","uploadfile/")

PicUrl=Request.Form("PicUrl")

Set objRegExp = New Regexp
objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = "<img.+?>"
strs=trim(content)

'是否偷图
if request.Form("getphoto")="1" then
Set Matches =objRegExp.Execute(strs)
For Each Match in Matches
RetStr = RetStr &getimgs( Match.Value )
Next 
end if 

function getimgs(str)
getimgs=""
Set objRegExp1 = New Regexp
objRegExp1.IgnoreCase = True
objRegExp1.Global = True
objRegExp1.Pattern = "http://.+?"""
set mm=objRegExp1.Execute(str)
For Each Match1 in mm
getimgs=getimgs&"||"&left(Match1.Value,len(Match1.Value)-1)
next
end function


function getHTTPPage(url)
on error resume next
dim http
set http=server.createobject("MSXML2.XMLHTTP")
Http.open "GET",url,false
Http.send()
if Http.readystate<>4 then 
exit function
end if
getHTTPPage=Http.responseBody
set http=nothing
if err.number<>0 then err.Clear 
end function
 

 
arrimg=split(retstr,"||")
allimg=""
newimg=""
for i=1 to ubound(arrimg)
if arrimg(i)<>"" and instr(allimg,arrimg(i))<1 then
fname="../uploadfile/"&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&cstr(i&mid(arrimg(i),instrrev(arrimg(i),".")))

dim geturl,objStream,imgs
geturl=trim(arrimg(i))
imgs=gethttppage(geturl)
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type =1
objStream.Open
objstream.write imgs
objstream.SaveToFile server.mappath(fname),2
objstream.Close()
set objstream=nothing

allimg=allimg&"||"&arrimg(i)
newimg=newimg&"||"&fname
end if
next

arrnew=split(newimg,"||")
arrall=split(allimg,"||")
for i=1 to ubound(arrnew)
arrnew(i)=replace(arrnew(i),"../uploadfile/","uploadfile/")
strs=replace(strs,arrall(i),arrnew(i))
arrnew(i)=replace(arrnew(i),"uploadfile/","")
if PicUrl=arrall(i) then
PicUrl=arrnew(i)
end if
next
content=strs

if left(Picurl,4)="http" then
fname="../uploadfile/"&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&cstr(i&mid(Picurl,instrrev(Picurl,".")))
dim imgsa
imgsa=gethttppage(Picurl)
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type =1
objStream.Open
objstream.write imgsa
objstream.SaveToFile server.mappath(fname),2
objstream.Close()
set objstream=nothing
aassss=Picurl
Picurl=fname
Picurl=replace(Picurl,"../uploadfile/","")
aassss1=Picurl
content=replace(content,aassss,"uploadfile/"&Picurl)
end if

if Content="" then
%>
<script language=javascript>
history.back()
alert("请输入文章内容！")
</script>
<%
Response.End
end if
if request.cookies("key")="super" then
if request("viewhtml")<>"" then 
%>
<script language=javascript>
history.back()
alert("请取消查看HTML源代码后再添加！")
</script>
<%
Response.End
end if
end if
SmallClassid=Request.Form("SmallClassid")
bigClassid=Request.Form("bigClassid")
typeid=Request.Form("typeid")
title=trim(request.form("title"))

if title="" then
%>
<script language=javascript>
history.back()
alert("请填写文章标题！")
</script>
<%
Response.End
end if

if len(title)>100 then
%>
<script language=javascript>
history.back()
alert("文章标题过长！")
</script>
<%
Response.End
end if
SpecialID=Request.Form("SpecialID")
SpecialID2=Request.Form("SpecialID2")
Author=replace(trim(Request.Form("Author")),"'","''")
Original=replace(trim(Request.Form("Original")),"'","''")
about=Request.Form("about")
if request.Form("PicUrl")="" then
picnews=0
else
picnews=1
end if
Picurl=replace(Picurl,"uploadfile/","")

editor=request.form("editor")
EnCode=Request.Form("EnCode")
newsrelated=Request.Form("newsrelated")
newslevel=Request.Form("newslevel")
title_color=Request.Form("title_color")
title_type=Request.Form("title_type")

set rs=server.createobject("adodb.recordset")
sql="select * from news" 
rs.open sql,conn,1,3
rs.addnew
rs("title")=title
rs("desc")=content
rs("EnCode")=EnCode
rs("newsrelated")=newsrelated
RS("classid")=request.Form("classid")
if title_type="" or title_type="0" then
rs("titletype")="l"
else
rs("titletype")=title_type
end if
rs("titlecolor")=title_color
rs("Time")=now()
rs.update
rs.Close
set rs=nothing
Response.cookies("content")=""
Response.cookies("newsrelated")=""
response.write "<p align=center><font color=red>恭喜您，文章“"&title&"”已经成功添加!<br>2秒钟后返回上页!</font>"
response.write "<meta http-equiv=""refresh"" content=""2;url=setnews.asp"">"
%>