Moved webcit display of user photo to the new protocol
authorArt Cancro <ajc@citadel.org>
Mon, 11 Apr 2016 15:13:18 +0000 (11:13 -0400)
committerArt Cancro <ajc@citadel.org>
Mon, 11 Apr 2016 15:13:18 +0000 (11:13 -0400)
citadel/modules/image/serv_image.c
webcit/static/t/user/show.html
webcit/static/t/who/bio.html
webcit/useredit.c
webcit/webcit.h

index 36f6838db2720f2c4dd65ee77b908c41beb22d0f..ff7d2e8e8910650d6675200103c5c10490251a83 100644 (file)
 #include <dirent.h>
 
 
+
+/*
+ * DownLoad User Image (see their avatar or photo or whatever)
+ * If this command succeeds, it follows the same protocol as the DLAT command.
+ */
+void cmd_dlui(char *cmdbuf)
+{
+       struct ctdluser ruser;
+       char buf[SIZ];
+
+       extract_token(buf, cmdbuf, 0, '|', sizeof buf);
+       if (CtdlGetUser(&ruser, buf) != 0) {
+               cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
+               return;
+       }
+       if (ruser.msgnum_pic < 1) {
+               cprintf("%d No image found.\n", ERROR + FILE_NOT_FOUND);
+               return;
+       }
+
+       struct CtdlMessage *msg = CtdlFetchMessage(ruser.msgnum_pic, 1, 1);
+       if (msg != NULL) {
+               // 600 402132|-1||image/gif|
+               safestrncpy(CC->download_desired_section, "1", sizeof CC->download_desired_section);
+               CtdlOutputPreLoadedMsg(msg, MT_SPEW_SECTION, HEADERS_NONE, 1, 0, 0);
+               CM_Free(msg);
+       }
+       else {
+               cprintf("%d No image found.\n", ERROR + MESSAGE_NOT_FOUND);
+               return;
+       }
+}
+
+
+
+
 /*
  * Import function called by import_old_userpic_files() for a single user
  */
@@ -159,6 +195,7 @@ CTDL_MODULE_INIT(image)
        if (!threading)
        {
                import_old_userpic_files();
+               CtdlRegisterProtoHook(cmd_dlui, "DLUI", "DownLoad User Image");
        }
        /* return our module name for the log */
         return "image";
index b957bd2525c782dfb397e589da521c617ac4804b..c9c599f1b4880a0dafa7b45630024a36830f33c3 100644 (file)
@@ -15,7 +15,7 @@
        <center>
          <table>
            <tr><td>
-               <??("COND:USER:PIC", 1, B"who")><img src="image?name=_userpic_?parm=<?BSTR("who", "U")>" alt=""><??("X", 1)>
+               <img src="userpic?user=<?BSTR("who", "U")>" alt="" border=0>
              </td><td><h1>
                  <?BSTR("who", "X")>
        </h1></td></tr>
index 32eafb0d91ee5a89b5d0317d564c716974b889b7..d5d2c0fb9a8e6e12ae4bf5e032ff481912e86fa6 100644 (file)
 <div id="content" class="service">
        <div id="bio_page">
                <div id="bio_pic">
-               <??("COND:USER:PIC", 1, B"who")><img src="image?name=_userpic_?parm=<?BSTR("who", "U")>" alt=""><??("X", 1)>
+               <img src="userpic?user=<?BSTR("who", "U")>" alt="" border=0>
                </div>
                <?!("X", 1)>
-               <div id="bio_title"><h1><<?BSTR("who", "X")></h1></div>
+               <div id="bio_title"><h1><?BSTR("who", "X")></h1></div>
                <div id="bio_text">
        <?USER:BIO(B"who", "FJUSTIFY")>
                </div>
index 2751ecde955b70c7fe6d54c2d065fb1f422f13d7..e7ba2b2bbb5e7beca0c102288ccbf563154c1ca7 100644 (file)
@@ -475,29 +475,11 @@ void tmplput_USER_BIO(StrBuf *Target, WCTemplputParams *TP)
        FreeStrBuf(&Buf);
 }
 
+
 int Conditional_USER_HAS_PIC(StrBuf *Target, WCTemplputParams *TP)
 {
-       StrBuf *Buf;
-       const char *who;
-       long len;
-       int r = 0;
-
-       GetTemplateTokenString(Target, TP, 2, &who, &len);
-
-       Buf = NewStrBuf();
-       serv_printf("OIMG _userpic_|%s", who);
-       StrBuf_ServGetln(Buf);
-       if (GetServerStatus(Buf, NULL) != 2) {
-               r = 1;
-       }
-       else {
-               r = 0;
-       }
-       serv_puts("CLOS");
-       StrBuf_ServGetln(Buf);
-       GetServerStatus(Buf, NULL);
-       FreeStrBuf(&Buf);
-       return(r);
+       // ajc 2016apr10 this needs to be re-evaluated with the new protocol
+       return(0);
 }
 
 
@@ -796,6 +778,30 @@ void create_user(void) {
 }
 
 
+void display_userpic(void) {
+       off_t bytes;
+       StrBuf *Buf = NewStrBuf();
+       const char *username = bstr("user");
+       serv_printf("DLUI %s", username);
+       StrBuf_ServGetln(Buf);
+       if (GetServerStatus(Buf, NULL) == 6) {
+               StrBufCutLeft(Buf, 4);
+               bytes = StrBufExtract_long(Buf, 0, '|');
+               StrBuf *content_type = NewStrBuf();
+               StrBufExtract_token(content_type, Buf, 3, '|');
+               WC->WBuf = NewStrBuf();
+               StrBuf_ServGetBLOBBuffered(WC->WBuf, bytes);
+               http_transmit_thing(ChrPtr(content_type), 0);
+               FreeStrBuf(&content_type);
+       }
+       else {
+               output_error_pic("", "");
+       }
+       FreeStrBuf(&Buf);
+}
+
+
+
 void _select_user_to_edit(void) {
        select_user_to_edit(NULL);
 }
@@ -814,6 +820,7 @@ InitModule_USEREDIT
        WebcitAddUrlHandler(HKEY("display_edituser"), "", 0, _display_edituser, 0);
        WebcitAddUrlHandler(HKEY("edituser"), "", 0, edituser, 0);
        WebcitAddUrlHandler(HKEY("create_user"), "", 0, create_user, 0);
+       WebcitAddUrlHandler(HKEY("userpic"), "", 0, display_userpic, 0);
 
        RegisterNamespace("USERLIST:USERNAME",      0, 1, tmplput_USERLIST_UserName, NULL, CTX_USERLIST);
        RegisterNamespace("USERLIST:PASSWD",        0, 1, tmplput_USERLIST_Password, NULL, CTX_USERLIST);
index 1509bf25ceca478da0f5d24b8bfed8979a4db837..fe34c23da6cd182463941962a8a4393b5e478ca1 100644 (file)
@@ -726,3 +726,4 @@ extern int DisableGzip;
 void display_summary_page(void);
 
 HashList *GetValidDomainNames(StrBuf *Target, WCTemplputParams *TP);
+void output_error_pic(const char *ErrMsg1, const char *ErrMsg2);