* map room-flags into conditionals
authorWilfried Göesgens <willi@citadel.org>
Thu, 20 Nov 2008 23:40:23 +0000 (23:40 +0000)
committerWilfried Göesgens <willi@citadel.org>
Thu, 20 Nov 2008 23:40:23 +0000 (23:40 +0000)
* more work on the central token escaping
* finetune BSTR tokens...
* finish message editing post/mail diversification
* add RFCA to our message the Reply button

webcit/messages.c
webcit/roomops.c
webcit/static/t/edit_message.html
webcit/static/t/view_message.html
webcit/subst.c
webcit/webcit.c
webcit/webcit.h

index ffbfab310826fa6d01c555fc9e1372c6f3a98a50..1cc4fa7a8a97ed65653e41bfc730d5e991ac7b69 100644 (file)
@@ -2114,6 +2114,8 @@ void display_enter(void)
                        goto DONE;
                }
        }
+       svputlong("RCPTREQUIRED", recipient_required);
+       svputlong("SUBJREQUIRED", recipient_required || subject_required);
        DoTemplate(HKEY("edit_message"), NULL, NULL, CTX_NONE);
        address_book_popup();
        wDumpContent(1);
index c87f4af0a77893369b6e86ada6de36ee62eb0de5..edbb48fd7e7868894fc98b9e33b0df674d53ab9f 100644 (file)
@@ -3689,7 +3689,74 @@ int ConditionalHaveUngoto(WCTemplateToken *Tokens, void *Context, int ContextTyp
                (strcasecmp(WCC->ugname, WCC->wc_roomname) == 0));
 }
 
-int ConditionalRoomHasQRVisidir(WCTemplateToken *Tokens, void *Context, int ContextType)
+
+
+
+int ConditionalRoomHas_QR_PERMANENT(WCTemplateToken *Tokens, void *Context, int ContextType)
+{
+       struct wcsession *WCC = WC;
+       
+       return ((WCC!=NULL) &&
+               ((WCC->room_flags & QR_PERMANENT) != 0));
+}
+
+int ConditionalRoomHas_QR_INUSE(WCTemplateToken *Tokens, void *Context, int ContextType)
+{
+       struct wcsession *WCC = WC;
+       
+       return ((WCC!=NULL) &&
+               ((WCC->room_flags & QR_INUSE) != 0));
+}
+
+int ConditionalRoomHas_QR_PRIVATE(WCTemplateToken *Tokens, void *Context, int ContextType)
+{
+       struct wcsession *WCC = WC;
+       
+       return ((WCC!=NULL) &&
+               ((WCC->room_flags & QR_PRIVATE) != 0));
+}
+
+int ConditionalRoomHas_QR_PASSWORDED(WCTemplateToken *Tokens, void *Context, int ContextType)
+{
+       struct wcsession *WCC = WC;
+       
+       return ((WCC!=NULL) &&
+               ((WCC->room_flags & QR_PASSWORDED) != 0));
+}
+
+int ConditionalRoomHas_QR_GUESSNAME(WCTemplateToken *Tokens, void *Context, int ContextType)
+{
+       struct wcsession *WCC = WC;
+       
+       return ((WCC!=NULL) &&
+               ((WCC->room_flags & QR_GUESSNAME) != 0));
+}
+
+int ConditionalRoomHas_QR_DIRECTORY(WCTemplateToken *Tokens, void *Context, int ContextType)
+{
+       struct wcsession *WCC = WC;
+       
+       return ((WCC!=NULL) &&
+               ((WCC->room_flags & QR_DIRECTORY) != 0));
+}
+
+int ConditionalRoomHas_QR_UPLOAD(WCTemplateToken *Tokens, void *Context, int ContextType)
+{
+       struct wcsession *WCC = WC;
+       
+       return ((WCC!=NULL) &&
+               ((WCC->room_flags & QR_UPLOAD) != 0));
+}
+
+int ConditionalRoomHas_QR_DOWNLOAD(WCTemplateToken *Tokens, void *Context, int ContextType)
+{
+       struct wcsession *WCC = WC;
+       
+       return ((WCC!=NULL) &&
+               ((WCC->room_flags & QR_DOWNLOAD) != 0));
+}
+
+int ConditionalRoomHas_QR_VISDIR(WCTemplateToken *Tokens, void *Context, int ContextType)
 {
        struct wcsession *WCC = WC;
        
@@ -3697,6 +3764,59 @@ int ConditionalRoomHasQRVisidir(WCTemplateToken *Tokens, void *Context, int Cont
                ((WCC->room_flags & QR_VISDIR) != 0));
 }
 
+int ConditionalRoomHas_QR_ANONONLY(WCTemplateToken *Tokens, void *Context, int ContextType)
+{
+       struct wcsession *WCC = WC;
+       
+       return ((WCC!=NULL) &&
+               ((WCC->room_flags & QR_ANONONLY) != 0));
+}
+
+int ConditionalRoomHas_QR_ANONOPT(WCTemplateToken *Tokens, void *Context, int ContextType)
+{
+       struct wcsession *WCC = WC;
+       
+       return ((WCC!=NULL) &&
+               ((WCC->room_flags & QR_ANONOPT) != 0));
+}
+
+int ConditionalRoomHas_QR_NETWORK(WCTemplateToken *Tokens, void *Context, int ContextType)
+{
+       struct wcsession *WCC = WC;
+       
+       return ((WCC!=NULL) &&
+               ((WCC->room_flags & QR_NETWORK) != 0));
+}
+
+int ConditionalRoomHas_QR_PREFONLY(WCTemplateToken *Tokens, void *Context, int ContextType)
+{
+       struct wcsession *WCC = WC;
+       
+       return ((WCC!=NULL) &&
+               ((WCC->room_flags & QR_PREFONLY) != 0));
+}
+
+int ConditionalRoomHas_QR_READONLY(WCTemplateToken *Tokens, void *Context, int ContextType)
+{
+       struct wcsession *WCC = WC;
+       
+       return ((WCC!=NULL) &&
+               ((WCC->room_flags & QR_READONLY) != 0));
+}
+
+int ConditionalRoomHas_QR_MAILBOX(WCTemplateToken *Tokens, void *Context, int ContextType)
+{
+       struct wcsession *WCC = WC;
+       
+       return ((WCC!=NULL) &&
+               ((WCC->room_flags & QR_MAILBOX) != 0));
+}
+
+
+
+
+
+
 int ConditionalHaveRoomeditRights(WCTemplateToken *Tokens, void *Context, int ContextType)
 {
        struct wcsession *WCC = WC;
@@ -3736,7 +3856,23 @@ InitModule_ROOMOPS
        WebcitAddUrlHandler(HKEY("set_floordiv_expanded"), set_floordiv_expanded, NEED_URL|AJAX);
        WebcitAddUrlHandler(HKEY("changeview"), change_view, 0);
        RegisterNamespace("ROOMBANNER", 0, 0, tmplput_roombanner, 0);
-       RegisterConditional(HKEY("COND:ROOM:FLAGS:QR_VISIDIR"), 0, ConditionalRoomHasQRVisidir, CTX_NONE);
+
+       RegisterConditional(HKEY("COND:ROOM:FLAGS:QR_PERMANENT"), 0, ConditionalRoomHas_QR_PERMANENT, CTX_NONE);
+       RegisterConditional(HKEY("COND:ROOM:FLAGS:QR_INUSE"), 0, ConditionalRoomHas_QR_INUSE, CTX_NONE);
+       RegisterConditional(HKEY("COND:ROOM:FLAGS:QR_PRIVATE"), 0, ConditionalRoomHas_QR_PRIVATE, CTX_NONE);
+       RegisterConditional(HKEY("COND:ROOM:FLAGS:QR_PASSWORDED"), 0, ConditionalRoomHas_QR_PASSWORDED, CTX_NONE);
+       RegisterConditional(HKEY("COND:ROOM:FLAGS:QR_GUESSNAME"), 0, ConditionalRoomHas_QR_GUESSNAME, CTX_NONE);
+       RegisterConditional(HKEY("COND:ROOM:FLAGS:QR_DIRECTORY"), 0, ConditionalRoomHas_QR_DIRECTORY, CTX_NONE);
+       RegisterConditional(HKEY("COND:ROOM:FLAGS:QR_UPLOAD"), 0, ConditionalRoomHas_QR_UPLOAD, CTX_NONE);
+       RegisterConditional(HKEY("COND:ROOM:FLAGS:QR_DOWNLOAD"), 0, ConditionalRoomHas_QR_DOWNLOAD, CTX_NONE);
+       RegisterConditional(HKEY("COND:ROOM:FLAGS:QR_VISIDIR"), 0, ConditionalRoomHas_QR_VISDIR, CTX_NONE);
+       RegisterConditional(HKEY("COND:ROOM:FLAGS:QR_ANONONLY"), 0, ConditionalRoomHas_QR_ANONONLY, CTX_NONE);
+       RegisterConditional(HKEY("COND:ROOM:FLAGS:QR_ANONOPT"), 0, ConditionalRoomHas_QR_ANONOPT, CTX_NONE);
+       RegisterConditional(HKEY("COND:ROOM:FLAGS:QR_NETWORK"), 0, ConditionalRoomHas_QR_NETWORK, CTX_NONE);
+       RegisterConditional(HKEY("COND:ROOM:FLAGS:QR_PREFONLY"), 0, ConditionalRoomHas_QR_PREFONLY, CTX_NONE);
+       RegisterConditional(HKEY("COND:ROOM:FLAGS:QR_READONLY"), 0, ConditionalRoomHas_QR_READONLY, CTX_NONE);
+       RegisterConditional(HKEY("COND:ROOM:FLAGS:QR_MAILBOX"), 0, ConditionalRoomHas_QR_MAILBOX, CTX_NONE);
+
        RegisterConditional(HKEY("COND:UNGOTO"), 0, ConditionalHaveUngoto, CTX_NONE);
        RegisterConditional(HKEY("COND:ROOM:EDITACCESS"), 0, ConditionalHaveRoomeditRights, CTX_NONE);
 
index 67e96dd6265b5e3227d40bffd9838aba5946df33..3c02d02cf1ca650b3dea77e69a6b37251eb658af 100644 (file)
@@ -12,8 +12,9 @@
 <input type="hidden" name="references" value="<?BSTR("references")>">
 
 <p class="send_edit_msg">
-  <input type="submit" name="send_button" value="<?_("Send message")>"> &nbsp;
-  <input type="submit" name="send_button" value="<?_("Post message")>"> &nbsp;TODO
+<?!("COND:SUBST", 1, "RCPTREQUIRED")><input type="submit" name="send_button" value="<?_("Send message")>"><?!("X", 1)>
+<??("COND:SUBST", 2, "RCPTREQUIRED")><input type="submit" name="send_button" value="<?_("Post message")>"><?!("X", 2)>
+&nbsp;
   <input type="submit" name="cancel_button" value="<?_("Cancel")>">
 </p>
 <img src="static/newmess3_24x.gif" class="imgedit">  <?DATE:NOW:STR>
 <tr><th><label for="from_id" >  <i><?_("from")></i> </label></th><td colspan="2">
 <select name="display_name" size=1 id="from_id">
 <?ITERATE("PREF:VALID:EMAIL:NAME", "section_msg_sender_name_select")>
+<?!("COND:ROOM:FLAGS:QR_ANONOPT", 3)>
+<option <?%("COND:BSTR", 1, "__ANONYMOUS__", "selected", "")> value="__ANONYMOUS__"><?_("Anonymous")></option>
+<?!("X", 3)>
 </select>
+
+<?!("COND:SUBST", 4, "RCPTREQUIRED")>
 <select name="my_email_addr" size=1>
 <?ITERATE("PREF:VALID:EMAIL:ADDR", "section_msg_sender_from_select")>
 </select>
+<?!("X", 4)>
+
  <i><?_("in")></i> <?ROOMNAME></td></tr>
+
+<?!("COND:SUBST", 5, "RCPTREQUIRED")>
 <tr>
   <th><label for="recp_id"> <?_("To:")></label></th>
   <td><input autocomplete="off" type="text" name="recp" id="recp_id" value="<?BSTR("recp", "H")>" size=45 maxlength=1000 />
 <script type="text/javascript">        
  activate_entmsg_autocompleters();     
 
-</script>                              
+</script>
+<??("X", 5)>           
 <tr>
   <th><label for="subject_id" > 
-      <?_("Subject:")><?_("Subject (optional):")><TODO>
+      <?!("COND:SUBST", 6, "SUBJREQUIRED")><?_("Subject:")><?!("X", 6)>
+      <??("COND:SUBST", 7, "SUBJREQUIRED")><?_("Subject (optional):")><??("X", 7)>
   </label></th>
   <td colspan="2">
     <input type="text" name="subject" id="subject_id" value="<?BSTR("subject", "U")>" size=45 maxlength=70>
index 0588167923062b508560ede546ae2fc7403f86d1..99fde203cff5ef84840270a396b88d9c1d3c2ed1 100644 (file)
@@ -5,14 +5,14 @@ onMouseOut=document.getElementById("msg<?MAIL:SUMM:N>").style.visibility="hidden
 <div class="message_header">
  <span><?MAIL:SUMM:DATESTR></span>
  <?_("from ")>
- <??("COND:MAIL:ANON",1)><a href="showuser?who=<?MAIL:SUMM:FROM("Q")>">"<?MAIL:SUMM:FROM("X")>"
-<?!("MAIL:SUMM:RFCA", 2)>&lt;<?MAIL:SUMM:RFCA>&gt;</a><?!("X", 2)>
-<??("MAIL:SUMM:RFCA", 3)></a> @ <?SERV:NODENAME><??("X", 3)>
+ <??("COND:MAIL:ANON",1)>
+<?!("MAIL:SUMM:RFCA", 2)><a href="showuser?who=<?MAIL:SUMM:FROM("Q")>">"<?MAIL:SUMM:FROM("X")>"&lt;<?MAIL:SUMM:RFCA>&gt;</a><?!("X", 2)>
+<??("MAIL:SUMM:RFCA", 3)><a href="showuser?who=<?MAIL:SUMM:FROM("Q")>"><?MAIL:SUMM:FROM("X")></a> @ <?SERV:NODENAME><??("X", 3)>
 <??("X", 1)>
  <?!("COND:MAIL:ANON", 4)>***<??("X", 4)>
  <p style="visibility: hidden;" id="msg<?MAIL:SUMM:N>" class="msgbuttons">
 
-   <a href="display_enter?recp=<?MAIL:SUMM:FROM("U")>&references=<?MAIL:SUMM:INREPLYTO("U")>%3C<?MAIL:SUMM:RFCA("U")>%3E&subject=<?MAIL:SUMM:SUBJECT("U", 0, "Re:%%20", "Re:")>"><span>[</span><?_("Reply")><span>]</span></a> 
+   <a href="display_enter?recp=%22<?MAIL:SUMM:FROM("U")>%22%3C<?MAIL:SUMM:RFCA("U")>%3E&references=<?MAIL:SUMM:INREPLYTO("U")>%3C<?MAIL:SUMM:RFCA("U")>%3E&subject=<?MAIL:SUMM:SUBJECT("U", 0, "Re:%%20", "Re:")>"><span>[</span><?_("Reply")><span>]</span></a> 
 
    <a href="display_enter?replyquote=<?MAIL:SUMM:N>&recp=<?MAIL:SUMM:FROM("U")>&references=<?MAIL:SUMM:INREPLYTO("U")>%3C<?MAIL:SUMM:RFCA("U")>%3E&subject=<?MAIL:SUMM:SUBJECT("U", 0, "Re:%%20", "Re:")>"><span>[</span><?_("ReplyQuoted")><span>]</span></a> 
 
index 3449489ab78e2e22c11db36ce6f662ed2163fe28..c77851bf8236c6e26c9830e452b3d9075b024224 100644 (file)
@@ -473,15 +473,30 @@ void StrBufAppendTemplate(StrBuf *Target,
                          int nArgs, 
                          WCTemplateToken *Tokens,
                          void *Context, int ContextType,
-                         StrBuf *Source, int FormatTypeIndex)
+                         const StrBuf *Source, int FormatTypeIndex)
 {
+        struct wcsession *WCC;
+       StrBuf *Buf;
        char EscapeAs = ' ';
 
-
+       if ((FormatTypeIndex < Tokens->nParameters) &&
+           (Tokens->Params[FormatTypeIndex]->Type == TYPE_STR) &&
+           (Tokens->Params[FormatTypeIndex]->len == 1)) {
+               EscapeAs = *Tokens->Params[FormatTypeIndex]->Start;
+       }
 
        switch(EscapeAs)
        {
-
+       case 'H':
+               WCC = WC;
+               Buf = NewStrBufPlain(NULL, StrLength(Buf));
+               StrBuf_RFC822_to_Utf8(Buf, 
+                                     Source, 
+                                     (WCC!=NULL)? WCC->DefaultCharset : NULL, 
+                                     NULL);
+               StrEscAppend(Target, Buf, NULL, 0, 0);
+               FreeStrBuf(&Buf);
+               break;
        case 'X':
                StrEscAppend(Target, Source, NULL, 0, 0);
                break;
@@ -903,6 +918,14 @@ int EvaluateConditional(StrBuf *Target, WCTemplateToken *Token, WCTemplate *pTmp
                return (state != 0)?Token->Params[1]->lvalue:0;
            
        Cond = (ConditionalStruct *) Token->PreEval;
+       if (Cond == NULL) {
+               lprintf(1, "Conditional [%s] (in '%s' line %ld); unknown![%s]\n", 
+                       Token->Params[0]->Start,
+                       ChrPtr(pTmpl->FileName),
+                       Token->Line,
+                       ChrPtr(Token->FlatToken));
+               return 1;
+       }
 
        if (Token->nParameters < Cond->nParams) {
                lprintf(1, "Conditional [%s] (in '%s' line %ld); needs %ld Params![%s]\n", 
index 91bbc4e86ac349c8755148e335f87288f8c4b70a..efeda29b50b383775b53790afc6e6bfe87e21038 100644 (file)
@@ -385,7 +385,10 @@ void hprintf(const char *format,...)
 void tmplput_trailing_javascript(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *vContext, int ContextType)
 {
        struct wcsession *WCC = WC;
-       StrBufAppendBuf(WCC->WBuf, WCC->trailing_javascript, 0);
+
+       if (WCC != NULL)
+               StrBufAppendTemplate(Target, nArgs, Tokens, vContext, ContextType,
+                                    WCC->trailing_javascript, 0);
 }
 
 /*
@@ -1907,6 +1910,11 @@ void tmplput_importantmessage(StrBuf *Target, int nArgs, WCTemplateToken *Tokens
        struct wcsession *WCC = WC;
        
        if (WCC != NULL) {
+/*
+               StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType,
+                                    WCC->ImportantMessage, 0);
+*/
+               WCC->ImportantMessage[0] = '\0';
                StrEscAppend(Target, NULL, WCC->ImportantMessage, 0, 0);
                        WCC->ImportantMessage[0] = '\0';
        }
@@ -1925,9 +1933,12 @@ int ConditionalBstr(WCTemplateToken *Tokens, void *Context, int ContextType)
 
 void tmplput_bstr(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
 {
-       StrBufAppendBuf(Target, 
-                       SBstr(Tokens->Params[0]->Start, 
-                             Tokens->Params[0]->len), 0);
+       const StrBuf *Buf = SBstr(Tokens->Params[0]->Start, 
+                           Tokens->Params[0]->len);
+       if (Buf != NULL)
+               StrBufAppendTemplate(Target, nArgs, Tokens, 
+                                    Context, ContextType,
+                                    Buf, 1);
 }
 
 
index ea94f6cea39743f6de6900384b09b14f6b46dde5..4aa951252ea98f3a7b0f5f4876a553d8ea24cd84 100644 (file)
@@ -374,7 +374,7 @@ void StrBufAppendTemplate(StrBuf *Target,
                          int nArgs, 
                          WCTemplateToken *Tokens,
                          void *Context, int ContextType,
-                         StrBuf *Source, int FormatTypeIndex);
+                         const StrBuf *Source, int FormatTypeIndex);