diff --git a/web/root/blogs/blog_config.js b/web/root/blogs/blog_config.js index ed903a1e553ba43983f7a783eeb3bf0d0e00144d..87690a574ca637d97495b6374c8932802453b069 100644 --- a/web/root/blogs/blog_config.js +++ b/web/root/blogs/blog_config.js @@ -16,20 +16,20 @@ var min_chars=400; // User name of the blogger var parameters=http_request.path_info.substr(1).split("/"); var poster=parameters[0]; -var year=parameters[1]; -var month=parameters[2]; -var day=parameters[3]; -var msgid=parameters[4]; +var year=parseInt(parameters[1],10); +var month=parseInt(parameters[2],10); +var day=parseInt(parameters[3],10); +var msgid=parseInt(parameters[4],10); var subject=parameters[5]; if(poster.indexOf("/")>=0) { poster=poster.substr(0,poster.indexOf("/")); } -var pnum=system.matchuser(poster); -if(pnum==0) { - write("<html><head><title>Error</title></head><body>Error getting UserID for "+poster+"!</body></html>"); - exit(1); -} +//var pnum=system.matchuser(poster); +//if(pnum==0) { +// write("<html><head><title>Error</title></head><body>Error getting UserID for "+poster+"!</body></html>"); +// exit(1); +//} var msgbase = new MsgBase(msg_code); if(!msgbase.open()) { @@ -37,7 +37,7 @@ if(!msgbase.open()) { exit(1); } -if(msgid != undefined && msgid != "") { +if(!isNaN(msgid)) { if(subject==undefined || subject=="") { var hdr=msgbase.get_msg_header(parseInt(msgid)); http_reply.status="301 Moved Permanently"; diff --git a/web/root/blogs/blog_item.xjs b/web/root/blogs/blog_item.xjs index bf9fcd294850419a596db7ee02dd8460f98a9ba7..d15cca6c2c1ad08dc08a66bc245a7d3b8222f256 100644 --- a/web/root/blogs/blog_item.xjs +++ b/web/root/blogs/blog_item.xjs @@ -1,5 +1,5 @@ <?xjs -load("/synchronet/src/web/root/blog/blog_config.js"); +load("/synchronet/src/web/root/blogs/blog_config.js"); ?> <html> @@ -13,50 +13,45 @@ load("/synchronet/src/web/root/blog/blog_config.js"); </p> <?xjs -var hdr=msgbase.get_msg_header(i); -if(hdr.from_ext != pnum) { - http_reply.status="404 Not Found"; - write("<html><head><title>Not found</title></head><body>The requested URL cannot be found.</body></hmtl>"); - exit(0); -} -if(hdr.thread_back) { +function not_found_error(reason) +{ http_reply.status="404 Not Found"; - write("<html><head><title>Not found</title></head><body>The requested URL cannot be found.</body></hmtl>"); + write("<html><head><title>Not found</title></head><body>The requested URL cannot be found. Reason: "+reason+"</body></hmtl>"); exit(0); } -var date=new Date(hdr.date); -if(year != undefined && year != "") { - if(date.getFullYear() != year) { - http_reply.status="404 Not Found"; - write("<html><head><title>Not found</title></head><body>The requested URL cannot be found.</body></hmtl>"); - exit(0); - } - if(month != undefined && month != "") { - if(date.getMonth()+1 != month) { - http_reply.status="404 Not Found"; - write("<html><head><title>Not found</title></head><body>The requested URL cannot be found.</body></hmtl>"); - exit(0); - } - if(day != undefined && day != "") { - if(date.getDate() != day) { - http_reply.status="404 Not Found"; - write("<html><head><title>Not found</title></head><body>The requested URL cannot be found.</body></hmtl>"); - exit(0); - } - } - } -} +var hdr=msgbase.get_msg_header(msgid); +if(hdr.from.toUpperCase() != poster.toUpperCase()) + not_found_error("poster"); +//if(hdr.from_ext != pnum) +// not_found_error("pnum"); + +if(hdr.thread_back) + not_found_error("top"); +var date=new Date(hdr.date); this_year=date.getFullYear(); this_month=date.getMonth()+1; this_day=date.getDate(); -var body=msgbase.get_msg_body(i, true); +if(year != this_year) + not_found_error("year"); + +if(month != this_month) + not_found_error("month "+month+"!="+this_month); + +if(day != this_day) + not_found_error("day"); + +if(subject != clean_subject(hdr.subject)) + not_found_error("subject"); + +var body=msgbase.get_msg_body(msgid, true); body=html_encode(body,true,true,false,false); -body=body.split(" ").join("</p><p>"); -body=body.split(" ").join(" "); +//body=body.split(" ").join("</p><p>"); +//body=body.split(" ").join(" "); +body=body.split(" ").join("<br>"); ?> <b><?xjs write(hdr.subject); ?></b> (<?xjs write(date); ?>)<br> @@ -65,10 +60,52 @@ body=body.split(" ").join(" "); <hr> <?xjs +// "Comments" +var thread_depth=0; +var skip=0; +/* Depth-first traversal of the thread */ +while(1) { + if(!skip && hdr.thread_first) { + msgid=hdr.thread_first; + thread_depth++; + skip=0; + } + else { + if(hdr.thread_next) { + msgid=hdr.thread_next; + skip=0; + } + else { + if(hdr.thread_back) { + msgid=hdr.thread_back; + hdr=msgbase.get_msg_header(msgid); + thread_depth--; + skip=1; + continue; + } + else + break; + } + } + hdr=msgbase.get_msg_header(msgid); + var body=msgbase.get_msg_body(msgid, true); + body=html_encode(body,true,true,false,false); + //body=body.split(" ").join("</p><p>"); + //body=body.split(" ").join(" "); + body=body.split(" ").join("<br>"); ?> +<div style="padding-left: <?xjs write(thread_depth*10) ?>px"> +<b><?xjs write(hdr.subject); ?></b> (<?xjs write(date); ?>)<br> +By: <?xjs write(hdr.from); ?><br> +<p><?xjs write(body); ?></p> <hr> +</div> + +<?xjs +} +?> </body> </html> diff --git a/web/root/blogs/index.xjs b/web/root/blogs/index.xjs index f9ce0b7e6818a0c684109089794b5b79e5335057..a8dd93f3e82db2878deae07311153c458b348209 100644 --- a/web/root/blogs/index.xjs +++ b/web/root/blogs/index.xjs @@ -1,6 +1,6 @@ <?xjs -load("/synchronet/src/web/root/blog/blog_config.js"); -if(msgid != undefined && msgid != "") { +load("/synchronet/src/web/root/blogs/blog_config.js"); +if(!isNaN(msgid)) { xjs_load("blog_item.xjs"); exit(0); } @@ -19,26 +19,28 @@ if(msgid != undefined && msgid != "") { <?xjs for(i=msgbase.last_msg; i>=msgbase.first_msg; i--) { var hdr=msgbase.get_msg_header(i); - if(hdr.from_ext != pnum) + if(hdr.from.toUpperCase() != poster.toUpperCase()) continue; +// if(hdr.from_ext != pnum) +// continue; if(hdr.thread_back) continue; var date=new Date(hdr.date); - if(year != undefined && year != "") { - if(date.getFullYear() != year) + this_year=date.getFullYear(); + this_month=date.getMonth()+1; + this_day=date.getDate(); + if(!isNaN(year)) { + if(year != this_year) continue; - if(month != undefined && month != "") { - if(date.getMonth()+1 != month) + if(!isNaN(month)) { + if(month != this_month) continue; - if(day != undefined && day != "") { - if(date.getDate() != day) + if(!isNaN(day)) { + if(day != this_day) continue; } } } - this_year=date.getFullYear(); - this_month=date.getMonth()+1; - this_day=date.getDate(); var body=msgbase.get_msg_body(i, true); j=min_chars; @@ -48,8 +50,9 @@ for(i=msgbase.last_msg; i>=msgbase.first_msg; i--) { var read_more=true; exerpt=body.substr(0,j); exerpt=html_encode(exerpt,true,true,false,false); - exerpt=exerpt.split(" ").join("</p><p>"); - exerpt=exerpt.split(" ").join(" "); +// exerpt=exerpt.split(" ").join("</p><p>"); +// exerpt=exerpt.split(" ").join(" "); + exerpt=exerpt.split(" ").join("<br>"); ?> <b><?xjs write(hdr.subject); ?></b> (<?xjs write(date); ?>)<br>