From 79c2898dd47f505daa49a2a1ca84b94761391c3e Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Fri, 15 Jul 2011 15:08:36 +0000 Subject: [PATCH] templatize userlist - move the little remaining stuff & needed functionality into useredit.c - hash users by UID, faster, plus also uniq, and more clever to search from LBIO. - utilize the new '1' parameter to LBIO so we can quickly locate users - modify the users found in LBIO to mark them having a bio - templatize userlist & user detailview. --- webcit/Makefile.in | 4 +- webcit/static/t/user/list.html | 17 +++ webcit/static/t/user/list_section.html | 9 ++ webcit/static/t/user/show.html | 27 ++++ webcit/useredit.c | 100 +++++++++++++-- webcit/userlist.c | 170 ------------------------- 6 files changed, 147 insertions(+), 180 deletions(-) create mode 100644 webcit/static/t/user/list.html create mode 100644 webcit/static/t/user/list_section.html create mode 100644 webcit/static/t/user/show.html delete mode 100644 webcit/userlist.c diff --git a/webcit/Makefile.in b/webcit/Makefile.in index 6a06a785b..fe9ea8d1b 100644 --- a/webcit/Makefile.in +++ b/webcit/Makefile.in @@ -49,7 +49,7 @@ webcit: webserver.o context_loop.o ical_dezonify.o \ cookie_conversion.o locate_host.o summary.o \ webcit.o auth.o tcp_sockets.o mainmenu.o serv_func.o who.o marchlist.o \ roomops.o roomlist.o roomtokens.o roomviews.o blogview_renderer.o \ - messages.o msg_renderers.o userlist.o paging.o sysmsgs.o \ + messages.o msg_renderers.o paging.o sysmsgs.o \ useredit.o vcard_edit.o preferences.o html2html.o listsub.o roomchat.o \ graphics.o netconf.o siteconfig.o subst.o bbsview_renderer.o \ calendar.o calendar_tools.o calendar_view.o tasks.o event.o smtpqueue.o \ @@ -65,7 +65,7 @@ webcit: webserver.o context_loop.o ical_dezonify.o \ webserver.o context_loop.o cookie_conversion.o marchlist.o \ webcit.o auth.o tcp_sockets.o mainmenu.o serv_func.o who.o listsub.o \ roomops.o roomlist.o roomtokens.o roomviews.o blogview_renderer.o \ - messages.o msg_renderers.o userlist.o paging.o sysmsgs.o \ + messages.o msg_renderers.o paging.o sysmsgs.o \ useredit.o locate_host.o siteconfig.o subst.o vcard_edit.o roomchat.o \ graphics.o netconf.o preferences.o html2html.o openid.o bbsview_renderer.o \ summary.o calendar.o calendar_tools.o calendar_view.o tasks.o event.o wiki.o \ diff --git a/webcit/static/t/user/list.html b/webcit/static/t/user/list.html new file mode 100644 index 000000000..eb3f08db5 --- /dev/null +++ b/webcit/static/t/user/list.html @@ -0,0 +1,17 @@ + + +
+ + + + + + + + + + +
+
diff --git a/webcit/static/t/user/list_section.html b/webcit/static/t/user/list_section.html new file mode 100644 index 000000000..1f456de7f --- /dev/null +++ b/webcit/static/t/user/list_section.html @@ -0,0 +1,9 @@ + + + + + +() + + + diff --git a/webcit/static/t/user/show.html b/webcit/static/t/user/show.html new file mode 100644 index 000000000..5434dbc67 --- /dev/null +++ b/webcit/static/t/user/show.html @@ -0,0 +1,27 @@ + + +
+ + +
+
+ + +
+ " alt=""> +

+ +

+
+ +
+ diff --git a/webcit/useredit.c b/webcit/useredit.c index 56b6622f2..81a5bd995 100644 --- a/webcit/useredit.c +++ b/webcit/useredit.c @@ -45,6 +45,7 @@ typedef struct _UserListEntry { /* Just available for Single users to view: */ unsigned int Flags; int DaysTillPurge; + int HasBio; } UserListEntry; @@ -272,9 +273,9 @@ HashList *iterate_load_userlist(StrBuf *Target, WCTemplputParams *TP) HashList *Hash = NULL; StrBuf *Buf; UserListEntry* ul; - char nnn[64]; - int nUsed; int len; + int UID; + void *vData; WCTemplputParams SubTP; memset(&SubTP, 0, sizeof(WCTemplputParams)); @@ -282,7 +283,7 @@ HashList *iterate_load_userlist(StrBuf *Target, WCTemplputParams *TP) Buf = NewStrBuf(); StrBuf_ServGetln(Buf); if (GetServerStatus(Buf, NULL) == 1) { - Hash = NewHash(1, NULL); + Hash = NewHash(1, Flathash); while (!Done) { len = StrBuf_ServGetln(Buf); @@ -296,9 +297,27 @@ HashList *iterate_load_userlist(StrBuf *Target, WCTemplputParams *TP) ul = NewUserListEntry(Buf); if (ul == NULL) continue; - nUsed = GetCount(Hash); - nUsed = snprintf(nnn, sizeof(nnn), "%d", nUsed+1); - Put(Hash, nnn, nUsed, ul, DeleteUserListEntry); + + Put(Hash, IKEY(ul->UID), ul, DeleteUserListEntry); + } + + serv_puts("LBIO 1"); + if (GetServerStatus(Buf, NULL) == 1) + while (!Done) { + len = StrBuf_ServGetln(Buf); + if ((len <0) || + ((len == 3) && + !strcmp(ChrPtr(Buf), "000"))) + { + Done = 1; + break; + } + UID = atoi(ChrPtr(Buf)); + if (GetHash(Hash, IKEY(UID), &vData) && vData != 0) + { + ul = (UserListEntry*)vData; + ul->HasBio = 1; + } } SubTP.Filter.ContextType = CTX_USERLIST; SortIt = RetrieveSort(&SubTP, HKEY("USER"), HKEY("user:uid"), 0); @@ -418,6 +437,65 @@ int ConditionalUserAccess(StrBuf *Target, WCTemplputParams *TP) == ul->AccessLevel; } +int ConditionalHaveBIO(StrBuf *Target, WCTemplputParams *TP) +{ + UserListEntry *ul = (UserListEntry*) CTX; + + if (ul == NULL) + return 0; + return ul->HasBio; +} + +void tmplput_USER_BIO(StrBuf *Target, WCTemplputParams *TP) +{ + int Done = 0; + StrBuf *Buf; + const char *who; + long len; + + GetTemplateTokenString(Target, TP, 0, &who, &len); + + Buf = NewStrBuf(); + serv_printf("RBIO %s", who); + StrBuf_ServGetln(Buf); + if (GetServerStatus(Buf, NULL) == 1) { + StrBuf *BioBuf = NewStrBufPlain(NULL, SIZ); + while (!Done && StrBuf_ServGetln(Buf)>=0) { + if ( (StrLength(Buf)==3) && + !strcmp(ChrPtr(Buf), "000")) + Done = 1; + else + StrBufAppendBuf(BioBuf, Buf, 0); + } + StrBufAppendTemplate(Target, TP, BioBuf, 1); + FreeStrBuf(&BioBuf); + } + FreeStrBuf(&Buf); +} + +int Conditional_USER_HAS_PIC(StrBuf *Target, WCTemplputParams *TP) +{ + StrBuf *Buf; + const char *who; + long len; + + GetTemplateTokenString(Target, TP, 2, &who, &len); + + Buf = NewStrBuf(); + serv_printf("OIMG _userpic_|%s", who); + StrBuf_ServGetln(Buf); + if (GetServerStatus(Buf, NULL) != 2) { + serv_puts("CLOS"); + StrBuf_ServGetln(Buf); + GetServerStatus(Buf, NULL); + FreeStrBuf(&Buf); + return 1; + } else { + FreeStrBuf(&Buf); + return 0; + } +} + /* * Locate the message number of a user's vCard in the current room @@ -433,7 +511,6 @@ long locate_user_vcard_in_this_room(message_summary **VCMsg, wc_mime_attachment void *vMsg; message_summary *Msg; wc_mime_attachment *Att; - int Done; StrBuf *Buf; long vcard_msgnum = (-1L); int already_tried_creating_one = 0; @@ -448,7 +525,6 @@ TRYAGAIN: Stat.maxload = 10000; Stat.lowest_found = (-1); Stat.highest_found = (-1); - Done = 0; /* Search for the user's vCard */ if (load_msg_ptrs("MSGS ALL||||1", &Stat, NULL) > 0) { at = GetNewHashPos(WCC->summ, 0); @@ -744,11 +820,14 @@ void _display_edituser(void) { display_edituser(NULL, 0); } +void showuser(void) { do_template("user_show");} + void InitModule_USEREDIT (void) { + WebcitAddUrlHandler(HKEY("showuser"), "", 0, showuser, 0); WebcitAddUrlHandler(HKEY("select_user_to_edit"), "", 0, _select_user_to_edit, 0); WebcitAddUrlHandler(HKEY("display_edituser"), "", 0, _display_edituser, 0); WebcitAddUrlHandler(HKEY("edituser"), "", 0, edituser, 0); @@ -767,9 +846,14 @@ InitModule_USEREDIT RegisterNamespace("USERLIST:FLAGS", 0, 0, tmplput_USERLIST_Flags, NULL, CTX_USERLIST); RegisterNamespace("USERLIST:DAYSTILLPURGE", 0, 0, tmplput_USERLIST_DaysTillPurge, NULL, CTX_USERLIST); + RegisterNamespace("USER:BIO", 1, 2, tmplput_USER_BIO, NULL, CTX_NONE); + RegisterConditional(HKEY("COND:USERNAME"), 0, ConditionalUser, CTX_USERLIST); RegisterConditional(HKEY("COND:USERACCESS"), 0, ConditionalUserAccess, CTX_USERLIST); RegisterConditional(HKEY("COND:USERLIST:FLAG:USE_INTERNET"), 0, ConditionalFlagINetEmail, CTX_USERLIST); + RegisterConditional(HKEY("COND:USERLIST:HAVEBIO"), 0, ConditionalHaveBIO, CTX_USERLIST); + + RegisterConditional(HKEY("COND:USER:PIC"), 1, Conditional_USER_HAS_PIC, CTX_NONE); RegisterIterator("USERLIST", 0, NULL, iterate_load_userlist, NULL, DeleteHash, CTX_USERLIST, CTX_NONE, IT_FLAG_DETECT_GROUPCHANGE); diff --git a/webcit/userlist.c b/webcit/userlist.c deleted file mode 100644 index a244a999d..000000000 --- a/webcit/userlist.c +++ /dev/null @@ -1,170 +0,0 @@ - -#include "webcit.h" - -/* - * structure to keep namelists in - */ -struct namelist { - struct namelist *next; /**< next item of the linked list */ - char name[32]; /**< name of the userentry */ -}; - -/* - * display the userlist - */ -void userlist(void) -{ - char buf[256]; - char fl[256]; - char title[256]; - struct tm tmbuf; - time_t lc; - struct namelist *bio = NULL; - struct namelist *bptr; - int has_bio; - int bg = 0; - - serv_puts("LBIO"); - serv_getln(buf, sizeof buf); - if (buf[0] == '1') - while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { - bptr = (struct namelist *) malloc(sizeof(struct namelist)); - bptr->next = bio; - strcpy(bptr->name, buf); - bio = bptr; - } - output_headers(1, 1, 2, 0, 0, 0); - wc_printf("
\n"); - wc_printf("

"); - snprintf(title, sizeof title, _("User list for %s"), ChrPtr(WC->serv_info->serv_humannode)); - escputs(title); - wc_printf("

"); - wc_printf("
"); - - wc_printf("
\n"); - - serv_puts("LIST"); - serv_getln(buf, sizeof buf); - if (buf[0] != '1') { - wc_printf("%s
\n", &buf[4]); - goto DONE; - } - - wc_printf("" - "", - _("User Name"), - _("Number"), - _("Access Level"), - _("Last Login"), - _("Total Logins"), - _("Total Posts")); - - while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { - extract_token(fl, buf, 0, '|', sizeof fl); - has_bio = 0; - for (bptr = bio; bptr != NULL; bptr = bptr->next) { - if (!strcasecmp(fl, bptr->name)) - has_bio = 1; - } - bg = 1 - bg; - wc_printf("\n", - extract_long(buf, 4), extract_long(buf, 5)); - - } - wc_printf("
\n"); - wc_printf("
%s%s%s%s%s%s
", - (bg ? "DDDDDD" : "FFFFFF") - ); - if (has_bio) { - wc_printf(""); - escputs(fl); - wc_printf(""); - } else { - escputs(fl); - } - wc_printf("%ld%d", - extract_long(buf, 2), - extract_int(buf, 1)); - lc = extract_long(buf, 3); - localtime_r(&lc, &tmbuf); - wc_printf("%02d/%02d/%04d ", - (tmbuf.tm_mon + 1), - tmbuf.tm_mday, - (tmbuf.tm_year + 1900)); - - - wc_printf("%ld%5ld
\n"); -DONE: wDumpContent(1); -} - - -/* - * Display (non confidential) information about a particular user - */ -void showuser(void) -{ - char who[256]; - char buf[256]; - int have_pic; - - strcpy(who, bstr("who")); - - output_headers(1, 1, 2, 0, 0, 0); - wc_printf("
\n"); - wc_printf("\"\""); - wc_printf("

"); - wc_printf(_("User profile")); - wc_printf("

"); - wc_printf(""); - wc_printf("
"); - - wc_printf("
\n"); - - wc_printf("
\n"); - - serv_printf("OIMG _userpic_|%s", who); - serv_getln(buf, sizeof buf); - if (buf[0] == '2') { - have_pic = 1; - serv_puts("CLOS"); - serv_getln(buf, sizeof buf); - } else { - have_pic = 0; - } - - wc_printf("
"); - if (have_pic == 1) { - wc_printf("\"\""); - } - wc_printf("

"); - escputs(who); - wc_printf("

\n"); - serv_printf("RBIO %s", who); - serv_getln(buf, sizeof buf); - if (buf[0] == '1') { - fmout("JUSTIFY"); - } - wc_printf("
\n"); - wDumpContent(1); -} - -void -InitModule_USERLIST -(void) -{ - WebcitAddUrlHandler(HKEY("userlist"), "", 0, userlist, 0); - WebcitAddUrlHandler(HKEY("showuser"), "", 0, showuser, 0); -} -- 2.30.2