#include #include #include #include #include "../fdpass.h" #include #include "util.h" using namespace std; #define trli_sessiond_client_test_NOTNEED #define trlid_client_listblogcomments_NOTNEED #define trlid_client_listblogs_NOTNEED #define trlid_client_addblogcomment_NOTNEED #define trlid_client_validnews_NOTNEED #define trlid_client_listcomments_NOTNEED #define trlid_client_listproofs_NOTNEED #define trlid_client_getcommentuser_NOTNEED #define trlid_client_getcomment_NOTNEED #define trlid_client_getproofuser_NOTNEED #define trlid_client_getproof_NOTNEED #define trlid_client_getnews_NOTNEED #define trlid_client_getnews_v2_NOTNEED #define trlid_client_getnews_v3_NOTNEED #define trlid_client_addcomment_NOTNEED #define trlid_client_addproof_NOTNEED #define trlid_client_addnews_NOTNEED #define trlid_client_confirmdelete_NOTNEED #define trlid_client_deleteuser_NOTNEED #define trlid_client_confirmuser_NOTNEED #define trlid_client_adduser_NOTNEED #define trlid_client_logout_NOTNEED #define trlid_client_login_NOTNEED #define trlid_client_getblog_NOTNEED #define trlid_client_getblogcomment_NOTNEED #define trlid_client_listsubjects_NOTNEED #define trlid_client_listarguments_NOTNEED #define trlid_client_getargument_NOTNEED #define trlid_client_addargument_NOTNEED #define trlid_client_addnewsurl_NOTNEED #define trlid_client_listnews_NOTNEED #define trlid_client_listnews_v1_NOTNEED #define trlid_client_listnews_v2_NOTNEED #define trlid_client_listnews_v3_NOTNEED #define trlid_client_listnews_v4_NOTNEED #define trlid_client_getstats_NOTNEED #define trlid_client_getextraurls_NOTNEED #define trlid_client_validextraurl_NOTNEED #include "../proto/trlid_client.protoch" #define trli_sessiond_client_getsessioninfo_NOTNEED #define trli_sessiond_client_setvar_NOTNEED #include "../proto/trli-sessiond_client.protoch" static string w_session; USERINFO userinfo; static W_UNSIGNED w_robot ("robot"); static const char *newscolor = "green"; static void trli_getsessioninfo(CONNECT_INFO &con, CONNECT_INFO &con_sess, const char *varname, unsigned &varval) { glocal const char *varname = varname; glocal unsigned *varval = &varval; glocal CONNECT_INFO *con = &con; (con_sess,w_session.c_str()); if (success){ userinfo.lang = lang; userinfo.name = name; userinfo.is_admin = admin; for (unsigned i=0; i(*glocal.con); w_session = sessionid; websession_setcookie("session",sessionid,time(NULL)+48*60*60); } } int util_getsessioninfo (CONNECT_INFO &con, CONNECT_INFO &con_sess,string &session, const char *varname, unsigned &varval) { if (tlmpweb_isrobot()) w_robot = 1; // debug { ("/tmp/agent.log",true); const char *pt = getenv ("HTTP_USER_AGENT"); if (pt == NULL){ fprintf (fout,"HTTP_USER_AGENT null\n"); }else{ fprintf (fout,"robot=%u HTTP_USER_AGENT %s\n",w_robot.getval(),pt); } return 0; } const char *ptsession = tlmpweb_getcookie("session"); if (ptsession == NULL){ (con); w_session = sessionid; websession_setcookie("session",sessionid,time(NULL)+48*60*60); }else{ w_session=ptsession; trli_getsessioninfo(con,con_sess,varname,varval); } session = w_session; if (w_session.empty()) return -1; return 0; } static void print_href_c (const char *title, const char *href, const char *color) { htmlprintf ("
 %s 
\n" ,href,color,title); } void print_href (const char *title, PARAM_STRING href) { print_href_c(title, href.ptr,"#33cc33"); } void print_aref (const char *page, const char *title, int step) { string href = string_f ("href=%s?webstep=%d style=\"text-decoration:none\"",page,step); print_href (title,href); } void print_aref (const char *title, int step) { print_aref (tlmpweb_curpage(),title,step); } void print_aref_selected (const char *page, const char *title, int step) { string href = string_f ("href=%s?webstep=%d style=\"text-decoration:none\"",page,step); print_href_c (title,href.c_str(),"#220022"); } void print_aref_selected (const char *title, int step) { print_aref_selected (tlmpweb_curpage(),title,step); } void print_aref_selected (const char *page, const char *title, int step, W_VAR &var) { string val = var.getvalstr(); string href = string_f ("href=%s?webstep=%d&%s=%s style=\"text-decoration:none\"",page,step,var.getname(),val.c_str()); print_href_c (title,href.c_str(),"#220022"); } void print_aref_selected (const char *title, int step, W_VAR &var) { print_aref_selected (tlmpweb_curpage(),title,step,var); } void print_aref (const char *page, const char *title, int step, W_VAR &var) { string val = var.getvalstr(); string href = string_f ("href=%s?webstep=%d&%s=%s style=\"text-decoration:none\"",page,step,var.getname(),val.c_str()); print_href (title,href); } void print_aref (const char *title, int step, W_VAR &var) { print_aref (tlmpweb_curpage(),title,step,var); } void print_aref (const char *title, int step, W_VAR &var1, W_VAR &var2) { string val1 = var1.getvalstr(); string val2 = var2.getvalstr(); string href = string_f ("href=%s?webstep=%d&%s=%s&%s=%s style=\"text-decoration:none\"",tlmpweb_curpage(),step ,var1.getname(),val1.c_str() ,var2.getname(),val2.c_str()); print_href (title,href); } void print_aref (const char *title, int step, W_VAR &var1, const char *varname2, const char *val2) { string val1 = var1.getvalstr(); string href = string_f ("href=%s?webstep=%d&%s=%s&%s=%s style=\"text-decoration:none\"",tlmpweb_curpage(),step ,var1.getname(),val1.c_str() ,varname2,val2); print_href (title,href); } void print_aref (const char *title, int step, W_VAR &var1, W_VAR &var2, W_VAR &var3) { string val1 = var1.getvalstr(); string val2 = var2.getvalstr(); string val3 = var3.getvalstr(); string href = string_f ("href=%s?webstep=%d&%s=%s&%s=%s&%s=%s style=\"text-decoration:none\"",tlmpweb_curpage(),step ,var1.getname(),val1.c_str() ,var2.getname(),val2.c_str() ,var3.getname(),val3.c_str()); print_href (title,href); } const char *format_line (const char *s) { while (*s != '\0' && *s != '\n'){ char car = *s++; if (car == '<'){ htmlout ("<"); }else if (car == '>'){ htmlout (">"); }else{ htmlout (car); } } return s; } const char *format_url (const char *s) { if (strncmp(s,"http://",7)!=0 && strncasecmp(s,"https://",8)!=0) htmlout ("http://"); return format_line (s); } void format_href(const char *s) { htmlout (""); if (strlen(s) > 50){ string tmp = string(s,80) + "..."; format_url(tmp.c_str()); }else{ format_url(s); } htmlout(""); } void format_content (const char *s, int nbline, bool &more) { more = false; bool ol_on = false; bool ul_on = false; bool quote_on = false; int noline = 0; while (*s != '\0' && noline < nbline){ if (*s == '\n'){ if (ul_on){ htmlout (""); ul_on = false; }else if (ol_on){ htmlout (""); ol_on = false; }else if (quote_on){ htmlout (""); quote_on = false; } htmlout ("

\n"); s++; noline++; }else{ const char *closing = ""; if (*s == '*'){ if (ol_on){ ol_on = false; htmlout (""); } if (!ul_on){ htmlout ("

    "); ul_on = true; } htmlout ("
  • "); s++; }else if (*s == '#'){ if (ul_on){ htmlout ("
"); ul_on = false; } if (!ol_on){ htmlout ("
    "); ol_on = true; } htmlout ("
  1. "); s++; }else if (*s == '?'){ s++; while (*s == ' ') s++; htmlout (""); s = format_url (s); htmlout (""); }else if (*s == '!'){ s++; if (*s == '!'){ s++; htmlout ("

    "); closing = "

    "; }else{ htmlout (""); closing = ""; } }else if (*s == '>'){ quote_on=true; s++; htmlout ("
    "); } s = format_line (s); noline++; htmlout (closing); if (*s == '\n'){ s++; htmlout ('\n'); } } } if (ul_on){ htmlout (""); } if (ol_on){ htmlout ("
"); } if (*s != '\0') more = true; } void format_content (const char *s) { bool more; format_content(s,10000,more); } void formatting_tips() { printhref ("/marker.html","Formatting tips",false); } void util_google_code() { #if 0 htmlout ("\n"); htmlout ("\n"); #endif } void util_defstyles() { htmlout ("\n" " \n"); } void printhref(const char *url, const char *text) { htmlprintf ("
 %s 
",url,text); } void printhref_selected(const char *url, const char *text) { htmlprintf ("
 %s 
",url,text); } void printhref(const char *url, const char *text, bool largewindow) { if (w_robot){ htmlprintf ("%s",url,text); }else{ const char *script = largewindow ? "myFunctionL" : "myFunction"; htmlprintf ("
 %s 
",script,url,text); } } void printhref_raw(const char *url, const char *text, bool largewindow) { if (w_robot){ htmlprintf ("%s",url,text); }else{ const char *script = largewindow ? "myFunctionL" : "myFunction"; htmlprintf ("%s",script,url,text); } } void print_date (PARAM_STRING pdate) { const char *date = pdate.ptr; if (strlen(date)==19){ int year = atoi(date); int month = atoi(date+5); int day = atoi(date+8); int hour = atoi(date+11); int minu = atoi(date+14); const char *ampm = "AM"; if (hour > 12){ hour -= 12; ampm="PM"; } static const char *tbmonth[]={"January","February","March","April","May","June","July","August","September","October","November","December"}; htmlprintf (" %s %d %04d @%d:%02d%s ",tbmonth[month-1],day,year,hour,minu,ampm); } } void util_formanchor() { htmlprintf ("\n"); } void button_preview(int step) { htmlprintf ("\n" ,tlmpweb_curpage(),step); } void button_row(_F_button_row &c, int border, const char *bgcolor) { htmlprintf ("\n",border,bgcolor); htmlout ("
\n"); htmlprintf ("\n",border,bgcolor); c.draw(); htmlout ("
\n"); htmlout ("
\n"); } void button_row(_F_button_row &c, int border) { button_row (c,border,"white"); } void button_row(_F_button_row &c) { button_row(c,0,"white"); } void _F_button_row::split() { htmlout ("\n"); } static unsigned subject=0; static W_UNSIGNED *w_tosubject; static const char *index_page = "/index.hc"; static void trli_space() { htmlprintf ("   \n"); } static void button_subject(const char *title, unsigned val) { trli_space(); (*w_tosubject)=val; if (subject != val){ print_aref (index_page,title,1,*w_tosubject); }else{ print_aref_selected (index_page,title,1,*w_tosubject); } } void trli_subjects (int step_statistics, int subject_selected, bool stat_selected, bool blog_selected, W_UNSIGNED &_w_tosubject) { glocal bool blog_selected = blog_selected; glocal bool stat_selected = stat_selected; glocal int step_statistics = step_statistics; w_tosubject = &_w_tosubject; subject = 1000; if (!stat_selected && !blog_selected) subject = subject_selected; htmlprintf ("\n"); htmlprintf ("\n"); if (w_robot == 0){ (0,newscolor); unsigned cur = w_tosubject->getval(); split(); htmlprintf (" Topics\n"); split(); button_subject ("All",0); split(); button_subject ("Peoples",1); split(); button_subject ("Technology",2); split(); button_subject ("Politic",3); split(); button_subject ("Sports",4); split(); button_subject ("Arts",5); split(); button_subject ("Economy",6); split(); button_subject ("Science",7); split(); trli_space(); if (glocal.blog_selected){ printhref_selected ("/blog.hc","Blog/Making of"); }else{ printhref ("/blog.hc","Blog/Making of"); } split(); trli_space(); const char *sitemap = "Sitemap/Stats"; if (glocal.stat_selected){ print_aref_selected (index_page,sitemap,glocal.step_statistics); }else{ print_aref (index_page,sitemap,glocal.step_statistics); } // Check max_subject above (*w_tosubject) = cur; } if (w_robot==0){ htmlprintf ("
\n"); htmlprintf ("\n"); } }