inherit "roxenlib"; #define htmlparse id->conf->modules["htmlparse"]->enabled #define ALLFILES indices(htmlparse->fton) #define ACC(X,Y) (htmlparse->query_num((X), Y)) #define CREATED(X) (htmlparse->database_created(X)) #define SET_CREATED(X,Y) (htmlparse->database_set_created(X,Y)) string mytime(int t) { mapping m=localtime(t); return sprintf("%s %d%s, %d", ({"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"})[m->mon], m->mday,([1:"st",21:"st",31:"st",2:"nd",22:"nd",3:"rd",23:"rd"])[m->mday]||"th", m->year+1900); } string fmtint(int i) { return ((string)i)/ -3.0 * ","; } class Data { string filename; int accessed; int modified; int created; } void insert(mapping files, string *file,int pos,Data all) { if(pos==sizeof(file)-1) { if(files[file[pos]]) { files[file[pos]]->accessed+=all->accessed; files[file[pos]]->modified=max(files[file[pos]]->modified, all->modified); files[file[pos]]->created=min(files[file[pos]]->created, all->created); }else{ files[file[pos]]=all; } }else{ if(!files[file[pos]]) files[file[pos]]=([0:file[..pos]*"/"]); insert(files[file[pos]],file,pos+1,all); } } array present(mapping f,mixed id) { int total; string ret=""; string *i=indices(f); for(int e=0;e\n" "\n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" "
Last modified:%s
Accessed:%s time%s since %s
\n", mytime(x->modified), fmtint(x->accessed), x->accessed==1?"":"s", mytime(x->created)); total+=x->accessed; } foreach(i-({"index.html"}),y) { mixed x=f[y]; if(object_program(x)==Data && stringp(y)) { string tmp; switch(lower_case((y/".")[-1])) { case "html": case "htm": tmp=sprintf("%s",x->filename,y); break; default: tmp=y; } ret+= sprintf( "
%s\n" "
\n" "\n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" "
Last modified:%s
Accessed:%s time%s since %s
\n", tmp, mytime(x->modified), fmtint(x->accessed), x->accessed==1?"":"s", mytime(x->created)); total+=x->accessed; } } foreach(i,y) { mixed x=f[y]; if(mappingp(x)) { string tmp; int hits; [ tmp,hits ]=present(x,id); total+=hits; if(strlen(tmp)) { string a=y; a-="~"; sscanf(a,"/%s",a); sscanf(a,"%s.html",a); sscanf(a,"http://%s",a); ret+= sprintf("
\n" "
  • %s/
    Directory total hits : %s\n" "
      \n" "%s\n" "
    \n",a,x[0],y,fmtint(hits),tmp); } } } if(!strlen(ret)) return ({"",total}); return ({ "
    \n"+ret+"
    \n",total }); } #define FILE(X) (dirname(__FILE__)+"/"+ (X)) #define READ(X) Stdio.read_file(FILE(X)) string *translate(string *data) { data=data[0..0] + (data[1..]-({""}) ); if(sizeof(data)>1) { switch(data[1]) { case "fuzzy": return ({"http://fuzzy.hubbe.net"})+data[2..]; case "abyss": return ({"http://abyss.hubbe.net"})+data[2..]; case "yume": return ({"http://yume.hubbe.net"})+data[2..]; case "~": switch(data[2]) { case "hubbe": return ({"http://fredrik.hubbe.net"})+data[3..]; case "munchkin": return ({"http://monica.hubbe.net"})+data[3..]; } break; case "~hubbe": return ({"http://fredrik.hubbe.net"})+data[2..]; case "~munchkin": return ({"http://monica.hubbe.net"})+data[2..]; case "sadie": return ({"http://sadie.hubbe.net"})+data[2..]; } } data[0]="http://www.hubbe.net"; return data; } mixed parse(object id) { mapping files=([]); foreach(sort(ALLFILES),string x) { Data d=Data(); if(search("//",x)==-1 && (d->accessed=ACC(x,0))) { if(string realfile=id->conf->real_file(x,id)) { if(mixed s=file_stat(realfile)) d->modified=s[3]; string *tmp=translate(x/"/"); d->filename=tmp*"/"; d->created=CREATED(x); insert(files,tmp,0,d); } } } string tmp; int hits; [ tmp,hits ]=present(files,id); return replace(READ("site_index.tmpl"),"$DATA", "
    Total number of hits for all sites on http://www.hubbe.net : "+ fmtint(hits)+ "

    \n"+ "

      \n"+ tmp+ "\n
    \n"); }