templatize userlist
authorWilfried Goesgens <dothebart@citadel.org>
Fri, 15 Jul 2011 15:08:36 +0000 (15:08 +0000)
committerWilfried Goesgens <dothebart@citadel.org>
Sun, 4 Sep 2011 21:36:35 +0000 (21:36 +0000)
  - 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
webcit/static/t/user/list.html [new file with mode: 0644]
webcit/static/t/user/list_section.html [new file with mode: 0644]
webcit/static/t/user/show.html [new file with mode: 0644]
webcit/useredit.c
webcit/userlist.c [deleted file]

index 6a06a785b8b7cea3d7f8101e0b24a9c9a57ee1fa..fe9ea8d1bd862331ed64af2c3de88c8c5f77593d 100644 (file)
@@ -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 (file)
index 0000000..eb3f08d
--- /dev/null
@@ -0,0 +1,17 @@
+<?=("head")>
+<div id="banner">
+  <h1><?_("User list for ")> <?SERV:HUMANNODE("X")></h1>
+</div>
+<div id="content" class="service">
+
+  <table class="userlist_background"><tr><td>
+       <tr>
+         <th><?_("User Name")></th>
+         <th><?_("Number")></th>
+         <th><?_("Access Level")></th>
+         <th><?_("Last Login")></th>
+         <th><?_("Total Logins")></th>
+         <th><?_("Total Posts")></th>
+       </tr>
+       <?ITERATE("USERLIST", ="user_list_section")>
+</table>
diff --git a/webcit/static/t/user/list_section.html b/webcit/static/t/user/list_section.html
new file mode 100644 (file)
index 0000000..1f456de
--- /dev/null
@@ -0,0 +1,9 @@
+<tr class="<?ITERATE:ODDEVEN>"><td>
+    <?!("COND:USERLIST:HAVEBIO", 1)><a href="showuser?who=<?USERLIST:USERNAME('U')>"><?USERLIST:USERNAME('X')></a><?!("X", 1)>
+    <??("COND:USERLIST:HAVEBIO", 2)><?USERLIST:USERNAME('X')><??("X", 2)>
+  </td>
+<td><?USERLIST:UID></td>
+<td><?USERLIST:ACCLVLSTR)>(<?USERLIST:ACCLVLNO>)</td>
+<td><?USERLIST:LASTLOGON:STR></td>
+<td><?USERLIST:NLOGONS></td>
+<td><?USERLIST:NPOSTS></td>
diff --git a/webcit/static/t/user/show.html b/webcit/static/t/user/show.html
new file mode 100644 (file)
index 0000000..5434dbc
--- /dev/null
@@ -0,0 +1,27 @@
+<?("=head")>
+<div id="banner">
+  <img src="static/webcit_icons/essen/32x32/account.png" alt="">
+  <h1><?_("User profile")></h1>
+  <div id="navbar">
+    <ul><li><a href="display_page?recp=<?BSTR("who", "U")>">
+          <img src="static/webcit_icons/essen/16x16/chat.png" alt="">
+         <span class="navbar_link">
+        <?_("Click here to send an instant message to")> <?BSTR("who", "X")> </span></li></a>
+  </div>
+</div>
+<div id="content" class="service bio">
+  <table class="userlist_background">
+    <tr><td>
+       <center>
+         <table>
+           <tr><td>
+               <??("COND:USER:PIC", 1, B"who")><img src="image?name=_userpic_&amp;parm=<?BSTR("who", "U")>" alt="">
+             </td><td><h1>
+                 <?BSTR("who", "X")>
+       </h1></td></tr>
+       </table>
+       </center>
+       <?USER:BIO(B"who", "FJUSTIFY")>
+  </td></tr>
+  </table>
+<?=("trailing">
index 56b6622f20295f87913fd2751e5a2824c4faa8d1..81a5bd99545c9c5d7e2ca6f1fb4dbecf74637f6e 100644 (file)
@@ -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 (file)
index a244a99..0000000
+++ /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("<div id=\"banner\">\n");
-       wc_printf("<h1>");
-       snprintf(title, sizeof title, _("User list for %s"), ChrPtr(WC->serv_info->serv_humannode));
-       escputs(title);
-       wc_printf("</h1>");
-        wc_printf("</div>");
-
-        wc_printf("<div id=\"content\" class=\"service\">\n");
-
-       serv_puts("LIST");
-       serv_getln(buf, sizeof buf);
-       if (buf[0] != '1') {
-               wc_printf("<em>%s</em><br>\n", &buf[4]);
-               goto DONE;
-       }
-
-       wc_printf("<table class=\"userlist_background\"><tr><td>\n");
-       wc_printf("<tr><th>%s</th><th>%s</th><th>%s</th>"
-                       "<th>%s</th><th>%s</th><th>%s</th></tr>",
-                       _("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("<tr bgcolor=\"#%s\"><td>",
-                       (bg ? "DDDDDD" : "FFFFFF")
-               );
-               if (has_bio) {
-                       wc_printf("<a href=\"showuser?who=");
-                       urlescputs(fl);
-                       wc_printf("\">");
-                       escputs(fl);
-                       wc_printf("</A>");
-               } else {
-                       escputs(fl);
-               }
-               wc_printf("</td><td>%ld</td><td>%d</td><td>",
-                       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("</td><td>%ld</td><td>%5ld</td></tr>\n",
-                       extract_long(buf, 4), extract_long(buf, 5));
-
-       }
-       wc_printf("</table>\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("<div id=\"banner\">\n");
-       wc_printf("<img src=\"static/webcit_icons/essen/32x32/account.png\" alt=\"\">");
-        wc_printf("<h1>");
-       wc_printf(_("User profile"));
-        wc_printf("</h1>");
-       wc_printf("<div id=\"navbar\">\n");
-       wc_printf("<ul><li><a href=\"display_page?recp=");
-       urlescputs(who);
-        wc_printf("\">"
-                "<img src=\"static/webcit_icons/essen/16x16/chat.png\" alt=\"\">"
-               "<span class=\"navbar_link\">");
-        snprintf(buf, sizeof buf, _("Click here to send an instant message to %s"), who);
-        escputs(buf);
-        wc_printf("</span></li></a>\n");
-       wc_printf("</div>");
-        wc_printf("</div>");
-
-        wc_printf("<div id=\"content\" class=\"service bio\">\n");
-
-       wc_printf("<table class=\"userlist_background\"><tr><td>\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("<center><table><tr><td>");
-       if (have_pic == 1) {
-               wc_printf("<img src=\"image?name=_userpic_&amp;parm=");
-               urlescputs(who);
-               wc_printf("\" alt=\"\">");
-       }
-       wc_printf("</td><td><h1>");
-       escputs(who);
-       wc_printf("</h1></td></tr></table></center>\n");
-       serv_printf("RBIO %s", who);
-       serv_getln(buf, sizeof buf);
-       if (buf[0] == '1') {
-               fmout("JUSTIFY");
-       }
-       wc_printf("</td></tr></table>\n");
-       wDumpContent(1);
-}
-
-void
-InitModule_USERLIST
-(void)
-{
-       WebcitAddUrlHandler(HKEY("userlist"), "", 0, userlist, 0);
-       WebcitAddUrlHandler(HKEY("showuser"), "", 0, showuser, 0);
-}