/* This file is part of Bolixo. Bolixo is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Bolixo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Bolixo. If not, see . */ #include #include #include #include #include #include #include #include #include #include #include #include #include #define DEFINE_USERINFO #include "util.h" #include "../bolixo.h" #include "../bolixo.m" #include #define INSTRUMENT_EXTERN #include "../instrument.h" #include #include "webtabs.h" #include "w_var.h" #include "steps.h" #include "document.h" #include #include "../proto/bod_client.protoch" extern bool is_mobile; // Create the URL to access the mini photo of a user, based on its ID static string news_get_mini_photo_url(const char *from, unsigned mini_image_width) { string user,server; if (splitline(from,'@',user,server)){ return string_f("\n" ,mini_image_width,server.c_str(),user.c_str()); }else{ return util_mini_img(step_public,mini_image_width,from,"project/mini-photo.jpg",""); } } void bolixo_news( CONNECT_INFO &con, CONNECT_INFO &con_sess, _F_websteps &websteps, vector &docpointers) { glocal docpointers; glocal con; glocal con_sess; glocal websteps; glocal IMAGES_SIZE imgsizes; static unsigned size[5]={15,40,45,0,0}; static unsigned size_mobile[5]={25,60,15,0,0}; ("news",tabs,is_mobile ? size_mobile : size); glocal map ids; // Find all the news group (or category) (glocal.con,w_session.c_str(),""); for (auto &u:users) glocal.ids[u.categ] = 0; // We are recreating all tabs, but we have to preserve the selorder // Find the selorder of previously defined tab if (glocal.ids.size() > 0){ for (auto &s: glocal.ids) s.second = get_selorder(s.first); auto p = glocal.ids.begin(); if (p->second == -1) p->second = (int)glocal.ids.size(); } cleartabs(WEBTAB_TYPE1); // For the first time we enter the main, we allocate for (auto &s: glocal.ids){ auto &categ = s.first; string title; if (categ.size() > 2){ if (isdigit(categ[0]) && categ[1] == '-'){ title = categ.substr(2); }else{ title = categ; } }else{ title = categ; } addtab(string_f("1:%s",categ.c_str()),title,s.second,true); } sethelp(); index_menu (sel_main,nullptr); glocal const char *id = id; glocal bool junk_output = false; // If the user hit "reply" in the drop down menu, we ditch everything // Also used for download vector output; tlmpweb_pushgrab(output); glocal string table; WEBID ID_FOLLOW("follow",glocal.id); glocal.table = ID_FOLLOW.c_str(); (ID_FOLLOW,currents[glocal.table],offsets[glocal.table],5); glocal unsigned dropmenu = dropmenu; glocal exit_webtable; vector empty; // Used twice (glocal.con,w_session.c_str(),"",empty,noline,1,firstseens[glocal.table].last ,glocal.id,empty,false); if (messages.size()!=1){ htmlprintf ("Internal error: %s\n",msg); }else{ auto &m = messages[0]; string filename,extension; index_msg_name(m.file_type,filename,extension); string suggested_name = string_f("%s.%s",filename.c_str(),extension.c_str()); string fname; unsigned step = step_image; if (m.inbox){ fname = string_f("/msgs/%s/short-inbox/inbox/%s",userinfo.name.c_str(),m.uuid); }else{ fname = string_f("/%s/msg/%s",m.from,m.uuid); step = step_public; } if (glocal.dropmenu == MENU_DOWNLOAD){ tlmpweb_popgrab(); tlmpweb_header ("Content-Disposition"," attachment; filename=%s" ,suggested_name.c_str()); if (m.inbox){ util_sendfile (glocal.con,w_session.c_str(),fname); }else{ util_sendpublicfile (glocal.con,fname); } glocal.junk_output = true; }else if (glocal.dropmenu == MENU_COPY){ string msg_name; if (m.inbox){ msg_name = fname; }else{ msg_name = string_f("/msgs/%s/short-inbox/public/%s",m.from,m.uuid); } index_setcopyitem(glocal.con,glocal.con_sess,msg_name,"",suggested_name); }else if (glocal.dropmenu == MENU_REPLY){ if (userinfo.name != m.from){ tlmpweb_forcevar(w_recipients,m.from); webtabs_forcevar(string_f("1:%s:inbox~%s",userinfo.name.c_str(),MSG_R(I_SHORTINBOX))); glocal.websteps.gotostep(step_talks); glocal.exit_webtable = true; glocal.junk_output = true; }else{ htmlprintf (MSG_R(E_REPLYTOYOU)); } }else if (file_is_image(m.file_type) || file_is_video(m.file_type) || file_is_sound(m.file_type)){ tlmpweb_popgrab(); glocal.junk_output = true; util_popup (glocal.con,step,m.content,m.file_type,m.submit,m.from ,fname); }else if (glocal.dropmenu == MENU_OPENINTAB){ string tabname(m.from); auto pos = tabname.find('@'); if (pos != string::npos) tabname = tabname.substr(0,pos); glocal.webtabs.addtab (string_f("2:%s",fname.c_str()),tabname); } } adddrop_opt (MENU_COPY,MSG_R(M_COPY)); adddrop_opt (MENU_DOWNLOAD,MSG_R(M_DOWNLOAD)); adddrop_opt (MENU_REPLY,MSG_R(M_REPLY)); adddrop_opt (MENU_OPENINTAB,MSG_R(M_OPENINTAB)); index_msgs_style (*this); glocal unsigned rownum = nbskip; auto &fseen = firstseens[glocal.table]; const char *last = fseen.last.c_str(); if (w_showhidden == 1){ last = ""; userinfo.main_notify = false; setcurrent(0); } vector empty; (glocal.con,w_session.c_str(),"",fulltext,nbskip,nblines,last,glocal.id,empty,false); // success:b msg messages:U{MAINMSG}v static const char *func = "Popup"; string day; static const char *line_styles[]={"sep","sep1"}; unsigned line_style = 0; if (nbnew==0) util_delnotify(glocal.con_sess,"main"); glocal.webtable.settotal(total); glocal.webtable.sethiddens(nbnew); glocal.webtable.sethidden_title(tlmpweb_ismobile() ? MSG_R(I_NEWM) : MSG_R(I_NEWMESSAGES)); if (glocal.rownum == 0 && nbnew == 0 && messages.size() > 0){ web_update_firstseen(glocal.con_sess,glocal.table,messages[0].uuid); } auto &previous_last = firstseens[glocal.table].previous; for (auto &m:messages){ if (index_is_full_select(m.content,m.uuid)){ tlmpweb_ctrloutput (true); bool truncated; string form_content = util_format_shortmsg (m.content,m.uuid ,0,m.size,glocal.imgsizes.image_width,truncated); htmlout (append_more_less (m.uuid,truncated,form_content,glocal.webtable,false)); tlmpweb_ctrloutput (false); glocal.webtable.setcurrent(glocal.rownum); return; } bool is_previous_last = previous_last == m.uuid; string now = string (m.submit,10); if (1){ if (m.inbox && userinfo.name != m.from){ glocal.webtable.setdrop_visible(MENU_REPLY); }else{ glocal.webtable.setdrop_hidden(MENU_REPLY); } } if (now != day){ day = now; glocal.webtable.setclickopt (true,"",""); glocal.webtable.setrow(is_previous_last ? "yline" : "hline",-1,"
%s
\a\a\a" ,format_date(userinfo.dateformat,day).c_str()); line_style=0; }else if (is_previous_last){ glocal.webtable.setclickopt (false,"",""); glocal.webtable.setrow("yline",-1,"
\a\a\a",is_mobile ? 15 : 5); } const char *style = line_styles[line_style]; line_style++; if (line_style == 2) line_style = 0; string time = string_f("
%s
",format_date(userinfo.dateformat,m.submit).c_str()); string img = news_get_mini_photo_url(m.from,glocal.imgsizes.mini_image_width); string path; unsigned step = step_image; if (m.inbox){ // Private message string add = string_f("webstep=%d&webtab_add=1:%s:inbox&recipients=%s" ,step_talks,userinfo.name.c_str(),m.from); glocal.webtable.setclickopt (true,"",add); path = string_f("/msgs/%s/short-inbox/inbox/%s",userinfo.name.c_str(),m.uuid); }else{ glocal.webtable.setclickopt (true,"",""); // Public message in the interest list path = string_f("%s/msg/%s",m.from,m.uuid); step = step_public; } string content; if (m.content[0] != '\0'){ bool truncated; string form_content = util_format_shortmsg (m.content,m.uuid,0,m.size ,glocal.imgsizes.image_width,truncated); content = append_more_less (m.uuid,truncated,form_content,glocal.webtable,true); }else if (file_is_sound(m.file_type)){ string tmp = util_flipspaces(m.submit); content = string_f("" ,tlmpweb_curpage(),step,path.c_str(),tmp.c_str(),tbftype[m.file_type]); }else if (file_is_image(m.file_type)){ content = util_img (step,glocal.imgsizes.image_width,"",path,m.submit); }else if (file_is_video(m.file_type)){ string tmp = util_flipspaces(m.submit); const char *extension = tbftype[m.file_type]; content = string_f( "" ,glocal.imgsizes.video_size,glocal.imgsizes.video_size ,tlmpweb_curpage(),step,path.c_str(),tmp.c_str(),extension); } { const char *private_msg = ""; string from; if (m.inbox){ private_msg = MSG_U(I_PRIVATE,"(private)"); from = m.from; }else{ const char *pt = strchr(m.from,'@'); string link; if (pt == NULL){ link = string_f("/public/%s",m.from); }else{ link = string_f("https://%s/public/%s",pt+1,string(m.from,pt-m.from).c_str()); } from = string_f("%s",link.c_str(),m.from); } glocal.webtable.setrow (style,glocal.rownum,"#%s\t%s %s\t%s",img.c_str(),private_msg,from.c_str() ,time.c_str()); if (file_is_sound(m.file_type)){ glocal.webtable.setclickopt (true,func,"400,100"); }else if (file_is_video(m.file_type)){ glocal.webtable.setclickopt (true,func,"800,800"); }else if (file_is_image(m.file_type)){ glocal.webtable.setclickopt (true,func,"800,800"); }else{ //if (!is_mobile) glocal.webtable.setclickopt (true,"",string_f("fullt=%s",m.uuid)); } glocal.webtable.setrow (style,glocal.rownum,"#\t%s\a",content.c_str()); } glocal.rownum++; }
tlmpweb_popgrab(); if (!glocal.junk_output){ tlmpweb_ctrloutput(true); //if (!w_fulltext.isset() && !w_select.isset()) bolixo_title ("",&glocal.websteps); htmlout (output); }
// tlmp_warning ("doctype2 id=%s\n",id); if (w_fulltext.isset() || w_select.isset()) return; // We skip everything here during a partial fetch if (strcmp(id,"help")==0){ DIV d("webtable"); d.print(); index_doc(glocal.docpointers[SECTION_MAIN],section_main); }else{ glocal string username; string filename; if (splitline(id,'/',match(""),glocal.username,match("msg"),filename)){ filename = "msg/" + filename; (glocal.con,glocal.username,filename,0); string time = format_date(userinfo.dateformat,info.modified); DIV l("tmp","tab_form"); l.dispflex().flowrow().print(); { DIV h; h.flexfixe().print(); string img = news_get_mini_photo_url (glocal.username.c_str(),glocal.imgsizes.mini_image_width); html_r_printf ("%s",img.c_str()); } { DIV h; h.flexfixe().paddings(30,0).print(); htmlout (glocal.username); } { DIV h; h.flexfixe().marginleftauto().print(); htmlout (time); } l.end(); DIV dd("webtable","text"); dd.autoscroll().w(100).bordertop(1,"black").print(); string buf ((const char*)content.getbuffer(),content.getsize()); bool truncated; string tmp = util_format_shortmsg (buf,"none",0,info.size,glocal.imgsizes.image_width,truncated); htmlout (tmp); }else{ tlmp_warning ("no match %s\n",id); } }
}