<!--#include file="../../lib/base.asp"-->
<!--#include file="../../theme/admin_leo/config.asp"-->
<!--#include file="../../lib/cmd.asp"-->
<%
''' EYCMS 内容替换插件
''' ==================================================================

    '注释：插件是否安装
    is_plug_install "eycms.plug.qrcode"
    
    '注释：管理权限检查
    is_plug_login
    
    '注释：定义插件模板路径
    dim plug_theme
    plug_theme="module/plug_qrcode/index.html"

    sub savedb()
        Dim code, sFileName
        sFileName = "temp.png"
        code = Trim(eycms.enhtml(eycms.fpost("data",0)))
        If code<>"" Then
            CreateFile sFileName, code
            downloadfile sFileName
        End If
    end sub

    Sub CreateFile(sFileName, sContent)
        sContent = "<?xml version=""1.0"" encoding=""gb2312""?>" & VbCrLf &_
            "<data>" & VbCrLf &_
            "<![CDATA[" & Mid(sContent, InStr(sContent, ",")+1) & "]]>" & VbCrLf &_
            "</data>"
        Dim sTempXmlFile, oFso, oFout, oXml, oAdos
        sTempXmlFile = "temp.xml"
        Set oFso  = Server.CreateObject("Scripting.FileSystemObject")
        Set oFout = oFso.CreateTextFile(Server.Mappath(sTempXmlFile))
        oFout.Write sContent
        oFout.Close
        Set oFout = Nothing
        Set oFso = Nothing
        Set oXml = Server.CreateObject("MSxml2.DOMDocument")
        Set oAdos = Server.CreateObject("ADODB.Stream")
        oXml.resolveExternals = False
        oXml.load Server.MapPath(sTempXmlFile)
        oXml.documentElement.setAttribute "xmlns:dt","urn:schemas-microsoft-com:datatypes"
        oXml.documentElement.dataType  =  "bin.base64"
        oAdos.Type = 1
        oAdos.Open
        oAdos.Write oXml.documentElement.nodeTypedValue
        oAdos.SaveToFile Server.MapPath(sFileName), 2
        oAdos.Close
        Set oXml = Nothing
        Set oAdos = Nothing
    End Sub

    function downloadfile(fullpath)
        downloadfile = False
        dim strfilename, s, fso, f, intfilelength
        set fso = server.createobject("scripting.filesystemobject")
        if not fso.fileexists(Server.MapPath(fullpath)) then
            exit function
        end If
        set f = fso.getfile(Server.MapPath(fullpath))
        intfilelength = f.size
        set s = server.createobject("adodb.stream")
        s.open
        s.type = 1
        s.loadfromfile(Server.MapPath(fullpath))
        response.buffer = true
        response.clear
        'response.addheader "Content-Encoding","UTF-8" ' 乱码的解决方案
        'response.addheader "content-type","application/x-msdownload"
        response.addheader "content-disposition","attachment;filename=" & f.name
        response.addheader "content-length" ,intfilelength
        response.contenttype = "application/octet-stream"
        while not s.eos
            response.binarywrite s.read(1024 * 64)
            response.flush
        wend
        s.close
        set s = Nothing
        f.close
        set f = nothing
        downloadfile = true
    end function

    dim act:act=lcase(eycms.fget("act",0))
    select case act
        case "shorturl":eycms.echo "{""status"":-1,""url"":null}"
        case "save":savedb
        case else:load plug_theme
    end select
    eycms.db.dbclose
%>
