c_autosaverjs.asp
上传用户:saigedz
上传日期:2019-10-14
资源大小:997k
文件大小:10k
源码类别:

中间件编程

开发平台:

HTML/CSS

  1. <%@CODEPAGE=65001 %>
  2. <% Option Explicit %>
  3. <% On Error Resume Next %>
  4. <% Response.Charset="UTF-8" %>
  5. <% Response.Buffer=True %>
  6. <%
  7. '///////////////////////////////////////////////////////////////////////////////
  8. '//              Z-Blog
  9. '// 作    者:    sipo
  10. '// 版权所有:    RainbowSoft Studio
  11. '// 技术支持:    rainbowsoft@163.com
  12. '// 程序名称:    
  13. '// 程序版本:    
  14. '// 单元名称:    c_autosaverjs.asp
  15. '// 开始时间:    2006-1-19
  16. '// 最后修改:    2006-7-27
  17. '// 备    注:    
  18. '///////////////////////////////////////////////////////////////////////////////
  19. %>
  20. <!-- #include file="../c_option.asp" -->
  21. <!-- #include file="../function/c_function.asp" -->
  22. <!-- #include file="../function/c_function_md5.asp" -->
  23. <!-- #include file="../function/c_system_lib.asp" -->
  24. <!-- #include file="../function/c_system_base.asp" -->
  25. <!-- #include file="../function/c_system_plugin.asp" -->
  26. <%
  27. Call System_Initialize()
  28. Public ZC_AUTOSAVE_FILENAME
  29. ZC_AUTOSAVE_FILENAME="autosave"&"_"&MD5(ZC_BLOG_HOST & ZC_BLOG_CLSID & BlogUser.Name)&".txt"  
  30. IF IsEmpty(ReQuest.QueryString("act")) Then
  31. SaveContent()
  32. ElseIf Request.QueryString("act")="edit" then
  33. ExportAutoSaveJS()
  34. End IF
  35. '*********************************************************
  36. ' 目的:    Convert Bytes To Str
  37. '*********************************************************
  38. Function BytesToBstr(body,Cset)
  39. On Error Resume Next
  40. Dim objstream
  41. Set objstream = Server.CreateObject("adodb.stream")
  42. objstream.Type = 1
  43. objstream.Mode =3
  44. objstream.Open
  45. objstream.Write body
  46. objstream.Position = 0
  47. objstream.Type = 2
  48. objstream.Charset = Cset
  49. BytesToBstr = objstream.ReadText 
  50. objstream.Close
  51. Set objstream = Nothing
  52. End Function
  53. '*********************************************************
  54. ' 目的:    Save Draft And DisPlay
  55. '*********************************************************
  56. Function SaveContent()
  57. If BlogUser.Level>3 Then
  58. Response.Write ZC_MSG259
  59. Response.End 
  60. End If
  61. On Error Resume Next
  62. Dim objStream
  63. Set objStream = Server.CreateObject("ADODB.Stream")
  64. With objStream
  65. .Type = 2
  66. .Mode = 3
  67. .Open
  68. .Charset = "utf-8"
  69. .Position = objStream.Size
  70. .WriteText=BytesToBstr(Request.BinaryRead(Request.TotalBytes),"UTF-8")
  71. .SaveToFile Server.MapPath("../CACHE/"&ZC_AUTOSAVE_FILENAME),2
  72. .Close
  73. End With
  74. Set objStream = NoThing
  75. If Err.Number=0 then
  76. Response.Write "<span style="""">&nbsp;"&formatdatetime(now,4)&":"&Right("0"&second(now),2)&"<a href="""&ZC_BLOG_HOST&"CACHE/"&ZC_AUTOSAVE_FILENAME&""" target=""_blank"" style=""text-decoration: none;"">"&ZC_MSG258&"</a>&nbsp;</span>"
  77. Else
  78. Response.Write "<span style="""">&nbsp;"&formatdatetime(now,4)&""&ZC_MSG257&"&nbsp;"&Err.Number&Err.description&"</span>"
  79. End If
  80. Response.End
  81. End Function
  82. '*********************************************************
  83. ' 目的:   输出自动保存脚本
  84. '*********************************************************
  85. Function ExportAutoSaveJS()
  86. Response.Clear
  87. '//////////////
  88. Response.Write "  function init(){"
  89. If Request.QueryString("type")="normal" Then Response.Write "init_edit();return postForm.value;"
  90. If Request.QueryString("type")="widgeditor" Then Response.Write "init_widgeditor();return postForm.innerHTML;"
  91. If Request.QueryString("type")="fckeditor" Then Response.Write "init_fckeditor();return postForm.innerHTML;"
  92. If Request.QueryString("type")="htmlarea" Then Response.Write "init_htmlarea();return postForm.innerHTML;"
  93. If Request.QueryString("type")="tinymce" Then Response.Write "init_tinymce();return postForm.innerHTML;"
  94. If Request.QueryString("type")="ewebeditor" Then Response.Write "init_ewebeditor();return postForm.innerHTML;"
  95. Response.Write "  }"
  96. Response.Write "  function restore(obj){"
  97. If Request.QueryString("type")="normal" Then Response.Write "init_edit();postForm.value=obj;"
  98. If Request.QueryString("type")="widgeditor" Then Response.Write "init_widgeditor();postForm.innerHTML=obj;"
  99. If Request.QueryString("type")="fckeditor" Then Response.Write "init_fckeditor();postForm.innerHTML=obj;"
  100. If Request.QueryString("type")="htmlarea" Then Response.Write "init_htmlarea();postForm.innerHTML=obj;"
  101. If Request.QueryString("type")="tinymce" Then Response.Write "init_tinymce();postForm.innerHTML=obj;"
  102. If Request.QueryString("type")="ewebeditor" Then Response.Write "init_ewebeditor();postForm.innerHTML=obj;"
  103. Response.Write "  }"
  104. '/////////////
  105. Response.Write "  var AutoSaveTime=60;"
  106. Response.Write "  var FileName="""&ZC_BLOG_HOST&"CACHE/"&ZC_AUTOSAVE_FILENAME&""";"
  107. Response.Write "  var postForm = null; "
  108. Response.Write "  var msg = null; "
  109. Response.Write "  function init_edit(){"
  110. Response.Write "  postForm = document.edit.txaContent;"
  111. Response.Write "  msg = document.getElementById(""msg"");"
  112. Response.Write "  }"
  113. '/////////////
  114. Response.Write "  function init_widgeditor(){"
  115. Response.Write "  postForm =document.getElementById('txaContentWidgIframe').contentWindow.document.getElementsByTagName('body')[0];"
  116. Response.Write "  msg = document.getElementById(""msg"");"
  117. Response.Write "  }"
  118. '/////////////
  119. Response.Write "  function init_fckeditor(){"
  120. Response.Write "  postForm =document.getElementById(""MyEditor___Frame"").contentWindow.frames[0].document.getElementsByTagName('body')[0];"
  121. Response.Write "  msg = document.getElementById(""msg"");"
  122. Response.Write "  }"
  123. '/////////////
  124. Response.Write "  function init_htmlarea(){"
  125. Response.Write "  postForm =document.getElementById('ta').parentNode.getElementsByTagName('iframe')[0].contentWindow.document.getElementsByTagName('body')[0];"
  126. Response.Write "  msg = document.getElementById(""msg"");"
  127. Response.Write "  }"
  128. '/////////////
  129. Response.Write "  function init_tinymce(){"
  130. Response.Write "  postForm =document.getElementById('mce_editor_0').contentWindow.document.getElementsByTagName('body')[0];"
  131. Response.Write "  msg = document.getElementById(""msg"");"
  132. Response.Write "  }"
  133. '/////////////
  134. Response.Write "  function init_ewebeditor(){"
  135. Response.Write "  postForm =document.getElementById('eWebEditor1').contentWindow.document.getElementsByTagName('body')[0];"
  136. Response.Write "  msg = document.getElementById(""msg"");"
  137. Response.Write "  }"
  138. '/////////////
  139. Response.Write "var ti=AutoSaveTime;"
  140. Response.Write "function savedraft()"
  141. Response.Write "{  init();"
  142. Response.Write " if (postForm!=null&&typeof(postForm)!=undefined){"
  143. Response.Write " var url = ""c_autosaverjs.asp"";"
  144. Response.Write " var postStr = init();"
  145. Response.Write " if (postStr){"
  146. Response.Write " var ajax = getHTTPObject();"
  147. Response.Write " ajax.open('POST', url, true); "
  148. Response.Write " ajax.setRequestHeader(""Content-Type"",""application/x-www-form-urlencoded""); "
  149. Response.Write " ajax.onreadystatechange = function(){if (ajax.readyState == 4 && ajax.status == 200) msg.innerHTML = ajax.responseText;};"
  150. Response.Write " ajax.send(postStr);"
  151. Response.Write " ti=-1000;"
  152. Response.Write " }else{"
  153. Response.Write " msg.innerHTML = """&ZC_MSG256&""";"
  154. Response.Write " ti=-1000;}"
  155. Response.Write " }else{msg.innerHTML = """&ZC_MSG255&""";ti=-1000;}"
  156. Response.Write "}"
  157. Response.Write "function restoredraft()"
  158. Response.Write "{ init();"
  159. Response.Write "if (window.confirm('"&ZC_MSG254&"'))"
  160. Response.Write "{"
  161. Response.Write " if (postForm!=null&&typeof(postForm)!=undefined){"
  162. Response.Write " var url = FileName;"
  163. Response.Write " var ajax = getHTTPObject();"
  164. Response.Write " ajax.open(""GET"", url+'?random='+Math.random(), true); "
  165. Response.Write " ajax.onreadystatechange = function() { "
  166. Response.Write " if (ajax.readyState == 4 && ajax.status == 200) { "
  167. Response.Write " restore(ajax.responseText);"
  168. Response.Write " msg.innerHTML ="""&ZC_MSG253&"""; } } ;"
  169. Response.Write " ajax.send(null); "
  170. Response.Write " ti=-1000;"
  171. Response.Write " }else{msg.innerHTML = """&ZC_MSG255&""";ti=-1000;}"
  172. Response.Write ""
  173. Response.Write "}"
  174. Response.Write "}"
  175. Response.Write "function Viewdraft()"
  176. Response.Write "{ "
  177. Response.Write "window.open(FileName,'','');"
  178. Response.Write "}"
  179. Response.Write "document.getElementById(""msg2"").innerHTML =""&nbsp;<a href='javascript:try{Viewdraft()}catch(e){};' style='cursor:hand;'>["&ZC_MSG015&"]</a>&nbsp;<a href='javascript:try{restoredraft()}catch(e){};' style='cursor:hand;'>["&ZC_MSG252&"]</a>&nbsp;<a href='javascript:try{savedraft()}catch(e){};' style='cursor:hand;'>["&ZC_MSG004&"]</a>"";"
  180. Response.Write "function timer() { "
  181. Response.Write "ti=ti-1;"
  182. Response.Write "var timemsg=document.getElementById(""timemsg"");timemsg.innerHTML = ti+"""&ZC_MSG251&""";"
  183. Response.Write "if (ti>=0){window.setTimeout(""timer()"", 1000);}else{if (ti<=-1000)"
  184. Response.Write "{ti=AutoSaveTime;timer();}else{timemsg.innerHTML = """&ZC_MSG250&"..."";savedraft"
  185. Response.Write "();ti=AutoSaveTime;timer();}} }"
  186. Response.Write "window.setTimeout(""timer()"", 0);"
  187. Response.Write "    function getHTTPObject() {"
  188. Response.Write " var xmlhttprequest=false; "
  189. Response.Write "    try {"
  190. Response.Write "   xmlhttprequest = new XMLHttpRequest();"
  191. Response.Write " } catch (trymicrosoft) {"
  192. Response.Write "   try {"
  193. Response.Write " xmlhttprequest = new ActiveXObject(""Msxml2.XMLHTTP"");"
  194. Response.Write "   } catch (othermicrosoft) {"
  195. Response.Write " try {"
  196. Response.Write "   xmlhttprequest = new ActiveXObject(""Microsoft.XMLHTTP"");"
  197. Response.Write " } catch (failed) {"
  198. Response.Write "   xmlhttprequest = false;"
  199. Response.Write " }"
  200. Response.Write "   }"
  201. Response.Write " }"
  202. Response.Write " return xmlhttprequest;"
  203. Response.Write "    }"
  204. End Function
  205. Call System_Terminate()
  206. %>