@name Database Browser
@inputs
@outputs Hist:array [Path Root]:string StartNum
@persist Hist:array [Path Root]:string StartNum
@trigger 
if(first()){
    Root="http://www1.dd-tech.com:9000/Dups/users/CaptainMaim/Morthotos/Expression2/"
    StartNum=Root:explode("/"):count()
}

runOnHTTP(1)
runOnChat(1)


O=owner()
Chat=O:lastSaid()

#List of acceptable words in chat this is the master string list of chat commands
Com="DB" #Database Browser
Dir="dir" #cause that's how it's done in DOS
Break="<" #I like this character for string parsing
Back="back" #to go back to the previous page you were at
Forward="next" #cause it's shorter than "forward", (broswer controls)

#chat string checks
COM=Chat:find(Com)
DIR=Chat:find(Dir)
BRK=Chat:find(Break)
BACK=Chat:find(Back)
FORWARD=Chat:find(Forward)


if(chatClk()&COM){ #standard command word activated chat command tree
    if(DIR){
        httpRequest(Root+Path) 
    }
        

}
if(httpClk()){
    Data=httpData()
    if(!httpRequestUrl():find(".txt")){
        List=array() #let's start with a blank slate
        List=Data:explode("HREF=") #pass1, find all directory entries
        for(C=1,List:count()){
            Item=httpUrlDecode(List[C,string]:explode(">")[1,string]) #crop the string to the end of the entry
            Item=Item:replace("&#39;","'") #repair any undecoded representations of apostrophy
            IL=Item:length() #get the length so we can crop off the extra quotes
            Item=Item:sub(2,IL-1) #crop the quotes off the first and last characters 
            List[C,string]=Item #resubmit the processed item to the list. 
        }
        List[1,string]="../" #just erase all the useless header crap and put a back directory entry instead.
    }else{ #You selected a file! 
        FilePath=Path:explode("/")
        File=FilePath[FilePath:count(),string]
        print("Saving "+File+" to E2shared with path.")
        fileWrite(">e2shared/"+Path,Data)
        
    }
}
