Private strHandle

Private Sub Class_Initialize()
    strHandle = Request.QueryString("Handle")
End Sub

Public Sub main()
    If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
        Call doPost
    Else
        Call doGet
    End If
End Sub

Private Sub doPost()
    Select Case LCase(strHandle)
    Case "remove"
        Call doPostRemove
    Case Else
    End Select    
End Sub

Private Sub doPostRemove()
    Response.Charset = "utf-8"
    Response.ContentType = "text/xml"
    Select Case LCase(Request.Form("Name"))
    Case "index"
        vbsre.cache("WAPmo.Index") = Empty
        vbsre.cache("WAPmo.User.Entry") = Empty
        Push "OK"
    Case "staple"
        Call doRemoveStaple
        Push "OK"
    Case "content"
        Call doRemoveContent
        Push "OK"
    Case Else
        Echo "δ֪"
    End Select
End Sub

Private Sub doRemoveStaple()
    Dim lngId
    lngId = atol(Request.Form("Id"))
    If lngId <= 0 Then
        Dim objParent
        Dim objFolder
        Set objParent = vbsre.fso.GetFolder(MyKernel.MapPath("cache"))
        For Each objFolder In objParent.SubFolders
            If LCase(Left(objFolder.Name, 6)) = "staple" Then
                doRemoveSingleStaple Mid(objFolder.Name, 7)
            End If
        Next
    Else
        doRemoveSingleStaple lngId
    End If
End Sub

Private Sub doRemoveSingleStaple(ByVal lngId)
    Dim strPath
    strPath = MyKernel.MapPath("cache/staple" & lngId)
    If vbsre.fso.FolderExists(strPath) = False Then Exit Sub
    Dim objFolder
    Dim objFile
    Set objFolder = vbsre.fso.GetFolder(strPath)
    For Each objFile In objFolder.Files
        If LCase(Left(objFile.Name, 6)) = "index_" Then
            vbsre.fso.DeleteFile strPath & "\" & objFile.Name
        End If
    Next
End Sub

Private Sub doRemoveContent()
    Dim lngId
    lngId = atol(Request.Form("Id"))
    If lngId <= 0 Then
        doRemoveAllContent MyKernel.MapPath("cache")
    Else
        doRemoveSingleContent lngId, atol(Request.Form("Follow")), atol(Request.Form("Time"))
    End If
End Sub

Private Sub doRemoveAllContent(ByVal strPath)
    Dim objParent
    Dim objFolder
    Dim objFile
    Set objParent = vbsre.fso.GetFolder(strPath)
    For Each objFolder In objParent.SubFolders
        doRemoveAllContent strPath & "\" & objFolder.Name
    Next
    For Each objFile In objParent.Files
        If LCase(Left(objFile.Name, 8)) = "content_" Then
            vbsre.fso.DeleteFile strPath & "\" & objFile.Name
        End If
    Next
End Sub

Private Sub doRemoveSingleContent(ByVal lngId, ByVal lngFollow, ByVal lngTime)
    Dim strPath
    strPath = MyKernel.MapPath("cache/staple" & lngFollow & "/" & FormatTime(getDate(lngTime), "YYYYMMDD"))
    If vbsre.fso.FolderExists(strPath) = False Then Exit Sub
    Dim objFolder
    Dim objFile
    Dim strKey
    Dim intKey
    Set objFolder = vbsre.fso.GetFolder(strPath)
    strKey = "content_" & lngId & "_"
    intKey = Len(strKey)
    For Each objFile In objFolder.Files
        If LCase(Left(objFile.Name, intKey)) = strKey Then
            vbsre.fso.DeleteFile strPath & "\" & objFile.Name
        End If
    Next
End Sub
