#include #include #include #include #include #include "../fdpass.h" #include #include "util.h" #include "../hostname.h" # using namespace std; #include "../proto/trlid_client.protoch" #include "../proto/trli-sessiond_client.protoch" static W_SSTRING w_content("content"); static W_UNSIGNED w_offmain ("offmain"); static W_UNSIGNED w_offcom ("offcom"); static W_UNSIGNED w_order ("order"); static unsigned order = 0; static W_SSTRING w_blogid ("blogid"); static W_UNSIGNED w_preview ("preview"); static const int step_main=1; static const int step_viewblog=2; static const int step_postcomment=3; static const char *newscolor = "green"; static const char *blogcolor = "deepskyblue"; static const char *newsstats = "WhiteSmoke"; static void show_buttons_right(_F_websteps *c) { /- /- /-
/- if (userinfo.name.empty()){ htmlprintf ("Anonymous, for your eyes only"); }else{ htmlprintf ("Welcome %s",userinfo.name.c_str()); int nb = 40 - userinfo.name.size() - 8; for (int i=0; i /-

} static void show_buttons_context(_F_websteps *c) { int step = c->getcurstep(); /- /- if (step < 2){ /-
unsigned old = w_order; w_order = order ? 0 : 1; print_aref (w_order ? "Switch order: old to new" : "Switch order: new to old",step_main,w_order); w_order = old; } if (step > 1){ /- print_aref ("Blog main page",step_main,w_offmain); } if (step == step_viewblog){ /- print_aref ("Add comment",step_postcomment,w_blogid); } /- /- /-
printhref ("/about.html","About " TRUELIES,true); /-
/-

} static W_UNSIGNED w_tosubject("tosubject"); static void trli_title (const char *title, _F_websteps *c) { string tmp = string_f (TRUELIES ": %s",title); tlmpweb_title (tmp.c_str()); util_google_code(); util_defstyles(); tlmpweb_body("white",NULL); htmlprintf (" /-
\n",newscolor); /-
tmp = string_f ("Truelies.news    %s",title); htmlprintf ("%s",tmp.c_str()); /- printhref ("/about.html","Where the truth lies...",true); /-
/-
show_buttons_right (c); /-
if (!tlmpweb_isrobot()){ trli_subjects (13, 1000, false,true,w_tosubject); } /-

show_buttons_context (c); } static void show_currentblog(CONNECT_INFO &con) { (con,w_blogid.c_str()); /-
/- htmlprintf (" /- //news_secondline (nickname,submit,url,nbproof,nbcomment); /- /-
\n",blogcolor); format_line (title); /-
/-
/- /- /-
/-

format_content (content); /-

/-

/-
/-
/-
}
static void show_onecomment (const char *blogid, const char *nickname, const char *submit, const char *content) { /- //htmlprintf (" ///- htmlprintf (" /-
\n" // ,tlmpweb_curpage(),0,w_blogid.c_str()); ///-
%s on\n",newsstats,nickname); print_date (submit); /-
/-
/- /- /-
/-

format_content (content); /-

/-

/-
/-
} static bool valid_context (CONNECT_INFO &con, _F_websteps *c, const char *subject, bool check_blog) { glocal bool ret = true; if (userinfo.name.empty()){ trli_title ("",c); /-

You must be logged to printf ("%s

\n",subject); glocal.ret = false; } if (check_blog){ (con,w_blogid.c_str()); if (!success) glocal.ret = false; } return glocal.ret; } extern "C" void webmain() { glocal string w_session; glocal CONNECT_INFO con; glocal CONNECT_INFO con_sess; glocal.con.port = "/dev/trlid.sock"; glocal.con.secret = "foo"; glocal.con_sess.port = "/dev/sessiond.sock"; glocal.con_sess.secret = "foo"; if (util_getsessioninfo (glocal.con,glocal.con_sess,glocal.w_session,"order",order)==-1) return; if (w_order.isset() && order != w_order){ string s = w_order.getvalstr(); (glocal.con_sess,glocal.w_session.c_str(),"order",s.c_str()); if (!success) printf ("Can't set variable order: %s\n",msg); order = w_order; } /-

(); if (step > 3){ step = 1; } trli_title ("",this); if (w_offmain > 0){ unsigned off = w_offmain; if (off > 20){ off -= 20; }else{ off = 0; } htmlprintf ("Previous blog entries\n" ,tlmpweb_curpage(),off); } (glocal.con,w_offmain,20,order); /- for (unsigned i=0; i /- htmlprintf (" } /-
\n" ,blogcolor,tlmpweb_curpage(),step_viewblog,blogids[i],w_offmain.getval()); format_line (titles[i]); /- htmlprintf ("%u comments",nbcomments[i]); /-
Submit on\n",newsstats); print_date (submits[i]); //news_secondline (nicknames[i],submits[i],urls[i],nbproofs[i],nbcomments[i]); /-
/-
/- /- /-
/-

bool more; format_content (contents[i],10,more); if (more){ htmlprintf ("
More ...\n" ,tlmpweb_curpage(),step_viewblog,blogids[i],w_offmain.getval()); } /-

/-

/-
/-
if (blogids.size() == 20){ htmlprintf ("Next blog entries\n" ,tlmpweb_curpage(),w_offmain+20); }
trli_title ("",this); show_currentblog (glocal.con); (glocal.con,w_blogid.c_str(),w_offcom,20); for (unsigned i=0; i if (valid_context(glocal.con,this,"add a comment",true)){ ("comment"); trli_title ("",&glocal.websteps); /-

sesssion htmlprintf (" %s

\n",glocal.w_session.c_str()); show_currentblog(glocal.con); /-

(0); split(); print_aref("Back to current blog",step_viewblog,w_blogid); split(); formatting_tips(); /-
/-
/- Preview

format_content (w_content.c_str()); /-

if (first){ (glocal.con,glocal.w_session.c_str(),w_blogid.c_str()); if (success){ w_content = content; } } /- field_hidden(w_blogid); /-
field_textarea (w_content,20,120,""); /-
button_submit ("Post"); button_preview (step_postcomment); /-
if (w_preview.getval() != 0) nothingtodo = false; bool ret = false; if (!w_content.empty()){ ret = true; } return ret; (glocal.con,glocal.w_session.c_str(),w_blogid.c_str(),w_content.c_str()); if (success){ glocal.websteps.gotostep(step_viewblog); }else{ ::printf ("success %d msg=%s\n",success,msg); } } }